I want to convert some existing AES code from M2Crypto to the equivalent pycrypto but the documentation is thin, especially for M2Crypto. I have reduced the relevant code to a gist. The main issues are:
padding
and key_as_bytes
to false encrypts to the same ciphertext with pycrypto. So I need to emulate padding=True
and key_as_bytes=True
in pure python.Any help would be much appreciated.
EDIT: Solved - the gist has been updated with the equivalent M2Crypto/pycrypto code and tests, I'll leave it there in case someone finds it useful in the future.
You will have to implement PKCS#7 padding/unpadding, which is kind of simple and specified in the publicly available standard from RSA labs, and of course on Wikipedia. Also see this answer:
AES 256 Encryption with PyCrypto using CBC mode - any weaknesses?
Note that PKCS#7 padding and PKCS#5 padding are identical, although the latter is officially only for 8 byte block ciphers (e.g. DES/TDEA). OpenSSL uses PKCS#7 padding by default.