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:
- Pycrypto requires the input to be multiple of 16 in length, m2crypto does not.
- Even when the input length is multiple of 16, the ciphertext differs. After experimenting with M2Crypto cipher parameters, it turns out that setting
padding
andkey_as_bytes
to false encrypts to the same ciphertext with pycrypto. So I need to emulatepadding=True
andkey_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.