[pycrypto] DES3 problem
Dave Pawson
dave.pawson at gmail.com
Sun Nov 24 06:50:27 PST 2013
https://www.dlitz.net/software/pycrypto/api/current/ states DES3 requires an iv.
in the api docs the example uses DES not DES3?
As an example, encryption can be done as follows:
>>> from Crypto.Cipher import DES
>>> from Crypto import Random
>>> from Crypto.Util import Counter
>>>
>>> key = b'-8B key-'
>>> nonce = Random.new().read(DES.block_size/2)
>>> ctr = Counter.new(DES.block_size*8/2, prefix=nonce)
>>> cipher = DES.new(key, DES.MODE_CTR, counter=ctr)
>>> plaintext = b'We are no longer the knights who say ni!'
>>> msg = nonce + cipher.encrypt(plaintext)
Using
iv=Random.new().read(DES3.block_size)
ciphere = DES3.new(key,mode,IV=iv)
I'm getting
Traceback (most recent call last):
File "./tester.py", line 405, in testBlock5
ciphere = DES3.new(key,mode,IV=iv)
File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/DES3.py",
line 114, in new
return DES3Cipher(key, *args, **kwargs)
File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/DES3.py",
line 76, in __init__
blockalgo.BlockAlgo.__init__(self, _DES3, key, *args, **kwargs)
File "/usr/lib64/python3.3/site-packages/Crypto/Cipher/blockalgo.py",
line 155, in __init__
raise ValueError("MODE_OPENPGP requires an IV")
ValueError: MODE_OPENPGP requires an IV
Am I wrong in my usage or is the code incorrect please
wrt iv parameter?
Tia
--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk
More information about the pycrypto
mailing list