crypto++ / pycrypto with google app engine

2019-02-15 13:15发布

I am using crypto++ to send AES encrypted http requests to app engine, planning to decrypt them there. My plan is to encrypt the portion after the '?' so it's something like:

http://myurl.com/Command?eiwjfsdlfjldkjfs when it is encrypted. However, I'm stuck figuring out how to decrypt it at the other end and still user get() on the response to get the args. Can someone advise if I am taking the wrong approach? Should I be decrypting and not using get() but my own parser then?

1条回答
Animai°情兽
2楼-- · 2019-02-15 13:50

I think you should create the URL like this:

http://myurl.com/Command?q=eiwjfsdlfjldkjfs

Then, in your request handler, you would be able to get the encrypted message like this:

encrypted_string = self.request.get('q')

EDIT:

This is how to do it:

1) to create the url:

import Crypto
from Crypto.Cipher import ARC4
obj=ARC4.new('stackoverflow')
plain = urllib.urlencode({'param1': 'v1', 'param2': 'v2'})
ciph = obj.encrypt(plain)
url = 'myurl.com/Command?%s' % urllib.urlencode({'q': ciph}) 
#url should be 'myurl.com/Command?q=%D4%2B%E5%FA%04rE.%1C.%81%0C%B6t%DCl%F8%84%EB'

2) to decrypt it:

ciph = self.request.get('q')
obj=ARC4.new('stackoverflow')
plain = obj.decrypt(ciph)
get_data = cgi.parse_qs(plain) # {'param2': ['v2'], 'param1': ['v1']}
查看更多
登录 后发表回答