python android aes
SmileChen007 opened this issue · comments
i use your aes jni in android project;
but i meet a problem;
android send the encrypt message to python server
but my python server can not decrypt the encrypt message ,
this is my python aes_utils
`class AESUtil:
__BLOCK_SIZE_16 = BLOCK_SIZE_16 = AES.block_size
@staticmethod
def encrypt(str, key):
cipher = AES.new(key, AES.MODE_ECB)
x = AESUtil.__BLOCK_SIZE_16 - (len(str) % AESUtil.__BLOCK_SIZE_16)
if x != 0:
str = str + chr(x) * x
msg = cipher.encrypt(str)
msg = base64.urlsafe_b64encode(msg).replace('=', '')
return msg
@staticmethod
def decrypt(enStr, key):
print ("---------->22")
cipher = AES.new(key, AES.MODE_ECB)
print ("---------->33 " + key)
enStr += (len(enStr) % 4) * "="
decryptByts = base64.urlsafe_b64decode(enStr)
msg = cipher.decrypt(decryptByts)
paddingLen = ord(msg[len(msg) - 1])
return msg[0:-paddingLen]`
AES has a complex encryption, configuration items are more, so try to use the same code, android is java call C, the server can use python call C to achieve.
请直接说中文,我想表达的是既然C可以跨平台,何不服务端跟客户端用同一套代码,安卓是用java调用C,你服务端可以python调用C,IOS可以Objective-c调用C,这样子实现代码统一,几乎不会出现任何问题,而且维护成本很低。