Pycrypto

Laszlo Nagy gandalf at designaproduct.biz
Fri Jun 16 08:14:43 EDT 2006


> 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.
>   
Or use CBC mode? I'm not familiar with pycrypto but I know that CBC mode 
can crypt/decrypt text with any size.

  Laszlo





More information about the Python-list mailing list