using cryptography instead of pycrypto for legacy wallet decryption

This commit is contained in:
Aaron Blankstein
2017-05-01 14:07:07 -04:00
parent c5219e376a
commit 1e02a7747e

View File

@@ -24,9 +24,8 @@
import base64
import scrypt
# TODO: deprecate use of Pycrypto by 0.16
from Crypto.Cipher import AES
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from binascii import hexlify, unhexlify
@@ -63,11 +62,13 @@ def aes_decrypt_legacy(payload, secret):
try:
PADDING = '{'
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
secret = ensure_length(secret)
cipher = AES.new(unhexlify(secret))
res = DecodeAES(cipher, payload)
cipher = Cipher(algorithms.AES(unhexlify(secret)), modes.ECB(),
backend = default_backend())
decryptor = cipher.decryptor()
res = decryptor.update(base64.b64decode(payload)) + decryptor.finalize()
res = res.rstrip(PADDING)
return res
except:
return None