I have some data that was encrypted using OpenSSL in C++ using aes_256_cbc and I need to decrypt it in Python. I figured using M2Crypto, being a wrapper for OpenSSL should make this easy but I’m not getting the same data out.
I’ve read the test_AES code and it hasn’t helped. I’m getting data out, it’s just not the right data.
c = Cipher(alg='aes_256_cbc', key=binaryKey, iv=iv, op=0, d='sha256', i=5, salt=knownSalt, padding=0)
v = c.update(binaryDataToDecrypt)
v += c.final()
At this point, afaik, v should be my data and it isn’t… I found another Q here on SO where it was mentioned that the first 16 bytes of the data to decrypt are the salt so I also tried the following with no luck:
c = Cipher(alg='aes_256_cbc', key=binaryKey, iv=iv, op=0, d='sha256', i=5, salt=binaryDataToDecrypt[0:16], padding=0)
v = c.update(binaryDataToDecrypt[16:])
v += c.final()
So the question I linked that mentioned slicing off the first 16 bytes may have been targeted to a different implementation. It turns out I had to slice off the final 16 bytes. You also have to make sure you’re slicing those 16 bytes off after you’ve converted the data into binary format so that it really is 16 bytes
Also, as mentioned in the comments by Paulo, AES doesn’t use salt so that parameter should be left to whatever the default is.