문제

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…

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top