python3: encoding variations in authentic.crypto aes utilities
This commit is contained in:
parent
8acaf31eb5
commit
cabb3476b0
|
@ -59,15 +59,15 @@ def aes_base64_encrypt(key, data):
|
|||
'''
|
||||
iv = Random.get_random_bytes(16)
|
||||
aes_key = PBKDF2(key, iv)
|
||||
aes = AES.new(aes_key, AES.MODE_CFB, iv)
|
||||
aes = AES.new(aes_key, AES.MODE_CFB, iv=iv)
|
||||
crypted = aes.encrypt(data)
|
||||
return '%s$%s' % (base64.b64encode(iv), base64.b64encode(crypted))
|
||||
return b'%s$%s' % (base64.b64encode(iv), base64.b64encode(crypted))
|
||||
|
||||
|
||||
def aes_base64_decrypt(key, payload, raise_on_error=True):
|
||||
'''Decrypt data encrypted with aes_base64_encrypt'''
|
||||
try:
|
||||
iv, crypted = payload.split('$')
|
||||
iv, crypted = payload.split(b'$')
|
||||
except (ValueError, TypeError):
|
||||
if raise_on_error:
|
||||
raise DecryptionError('bad payload')
|
||||
|
@ -80,7 +80,7 @@ def aes_base64_decrypt(key, payload, raise_on_error=True):
|
|||
raise DecryptionError('incorrect base64 encoding')
|
||||
return None
|
||||
aes_key = PBKDF2(key, iv)
|
||||
aes = AES.new(aes_key, AES.MODE_CFB, iv)
|
||||
aes = AES.new(aes_key, AES.MODE_CFB, iv=iv)
|
||||
return aes.decrypt(crypted)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue