[pycrypto] AES, python 2.7 vs 3

Dave Pawson dave.pawson at gmail.com
Mon Feb 3 06:14:25 PST 2014


  iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
    print("key is %d, iv is %d" % (len(key), len(iv)))
    encryptor = AES.new(key, AES.MODE_CBC, iv)

prints 16 bytes for both key and iv.

runs fine under python 2.7.5
Under python 3

key is 16, iv is 16
Traceback (most recent call last):
  File "testNL.py", line 134, in <module>
    encrypt_file(key,plainfile,encfile)
  File "testNL.py", line 40, in encrypt_file
    encryptor = AES.new(key, AES.MODE_CBC, iv)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/AES.py", line
95, in new
    return AESCipher(key, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/AES.py", line
59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/blockalgo.py",
line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
ValueError: IV must be 16 bytes long


yet again the print statement shows 16 for the length of both?

Any suggestions where to start looking please?

DaveP


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk


More information about the pycrypto mailing list