Search code examples
pythonencryptionaesmcryptpycrypto

AES encryption with PyCrypto and decryption with mcrypt


For some sensitive data I decided to store it AES-encrypted on disc. I've implemented the encryption using PyCrypto.

Furthermore, the data is important, and the stored encrypted data will be my only copy of it (backups aside), so I looked for some means of retrieving the data without using PyCrypto to have a fallback given the possibility that PyCrypto is not longer available to me (for whatever reason that may be).

I thought mcrypt could be an option.

This is my test case to get some ciphertext written:

import Crypto.Cipher.AES
import sys

pwd  = 'qwertzuiopasdfgh'
mode = Crypto.Cipher.AES.MODE_CBC
aes  = Crypto.Cipher.AES.new( pwd, mode )
text = 'asdfghjklyxcvbnm'
sys.stdout.write( aes.encrypt( text ) )

I redirected the output to a file out.nc and tried decryption by

mcrypt -d -b -k qwertzuiopasdfgh -a rijndael-128 -m CBC out.nc

but the resulting file out has zero bytes size, unfortunately.

I hope there is a combination of options to mcrypt to make this work…


Solution

  • Why is it important to be able to recover without PyCrypto? You can simply fire up a VM with the old OS and the old release of PyCrypto, export your data, and re-encrypt with a different algorithm and implementation.