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 gi开发者_StackOverflow社区ven 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…
I think the problem may lay in the fact that you don't supply an IV for CBC mode and without an IV maybe mCrypt and PyCrypto handle it differently by using different default IVs. I have seen some implementations (phpseclib for instance) use and IV of 16 null bytes by default. mcrypt might not do this.
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.
精彩评论