AES decrypting in Python

Mike Driscoll kyosohma at gmail.com
Wed Oct 7 16:37:13 CEST 2009


Hi,

I am working on a project where I need to decrypt some data that has
been encrypted with AES. It looks like M2Crypto is the module of
choice for these sorts of things, but I cannot figure out how to do
this stuff from the docs. I have the following PHP code that needs to
be translated into Python:

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key,
$data,MCRYPT_MODE_ECB, $iv),"\0");

I can't find a method in M2Crypto that gets the "initialization
vector" size. I found the right method in the tests, which appears to
be EVP.Cipher. So I would assume, I would need to do something like:

EVP.Cipher(alg="aes_256_ecb", key=SomeKey, iv=SomeIV, op=dec,
padding=False)

I don't really see where I pass the data that needs the decrypting
though. Can someone shed some light on this?

Thanks,

Mike



More information about the Python-list mailing list