[pycrypto] Pycrypto openssl interoperability

Richard Moore richmoore44 at gmail.com
Thu Dec 16 07:44:25 CST 2010


I'm new to pycrypto and have playing around with it a bit. I can
successfully encrypt and decrypt things using the library, however in
order to check I was doing things correctly, I've tried to decrypt
something encrypted with openssl - sadly without success.

Encrypt the file secrets.txt using openssl, AES 128bit CBC. The
password is read from the file pass.txt:

openssl enc -aes-128-cbc -pass file:pass.txt -a -in secrets.txt -out

Then decrypt the result using pycrypto:

from Crypto.Cipher import AES
from base64 import b64encode, b64decode

f = open('pass.txt')
key = f.read()
aes = AES.new(key, AES.MODE_CBC)

f = open('secrets.txt.enc')
b64_cipher_text = f.read()
cipher_text = b64decode(b64_cipher_text)
print aes.decrypt(cipher_text)

Can anyone tell me where I'm going wrong, or perhaps has an example of
working interoperability with openssl?



More information about the pycrypto mailing list