[pycrypto] PyCrypto 2.3 and unicode

Thomas Knox knoxth at gmail.com
Mon May 16 13:18:26 CST 2011


Hello,

I'm building an application in Python 2.7.1 using PyCrypto 2.3, and it's
behaving badly with utf-8 and utf-16 strings. For example:

from Crypto.Cipher import AES
foo = AES.new('a1b2c3d4e5f6g7h8', AES.MODE_ECB)
bar=u''
for i in range(0,16):
    bar+=unichr(255)
# At this point, bar is
# u'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'
baz=foo.encrypt(bar.encode('utf-8'))
blah=foo.decrypt(baz)
# baz is now
#
'\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf\xc3\xbf'

How can I get encrypt and decrypt to use UTF gracefully?

Thank you,
Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.dlitz.net/pipermail/pycrypto/attachments/20110516/07a6ddd9/attachment.htm 


More information about the pycrypto mailing list