Pycrypto

wittempj@hotmail.com martin.witte at gmail.com
Fri Jun 16 07:52:32 EDT 2006


luca72 wrote:
> Hello
> I have to make an easy operation but reading the pycrypto doc. a never
> see AES example
> I have to cript this key 'ea523a664dabaa4476d31226a1e3bab0' with the
> AES.
> Can you help me for make it with pycrypto
>
> Regards Luca

You can do this as follows:

py> from Crypto.Cipher import AES
py> # key has to be 16, 24 or 32 bytes for AES
py> crypt = AES.new('abcdefghijklmnop', AES.MODE_ECB)
# we're lucky, the string to encrypt is a multiple of 16 in length
py> txt = 'ea523a664dabaa4476d31226a1e3bab0'
py> c = crypt.encrypt(txt)
py> c
'w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa\xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\xb9'
py> crypt.decrypt(c)
'ea523a664dabaa4476d31226a1e3bab0'

see http://www.amk.ca/python/writing/pycrypt for the docs. if you have
to encrypt data which has not a multiple of length 16 you have to pad
it e.g. with spaces, and then strip the decrypt() result.




More information about the Python-list mailing list