Pycrypto

wittempj@hotmail.com martin.witte at gmail.com
Fri Jun 16 14:50:37 CEST 2006


Laszlo Nagy wrote:
> > 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

Not in this implementation:
py> from Crypto.Cipher import AES
py> crypt = AES.new('abcdefghijklmnop', AES.MODE_CBC)
py> c = crypt.encrypt('1')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: Input strings must be a multiple of 16 in length




More information about the Python-list mailing list