P
Paul Pittlerson
I seem to have misunderstood something about the way Crypto.Cipher is supposed to work, because I'm getting unexpected results, here is my code..
import hashlib
from Crypto.Cipher import AES
from Crypto import Random
h = hashlib.new('sha256')
h.update('my key')
key = h.digest()
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CFB, iv)
txt = 'hello world'
# This is the part where I'm confused, because it seems like encrypt will output a different result every time, so how can I decrypt it?
msg = cipher.encrypt(txt)
msg = cipher.encrypt(txt)
# etc
# it works like I would expect the first time when decrypting, if I follow the example from pycrypto docs:
msg = iv + cipher.encrypt(txt)
cipher.decrypt(iv + msg)
# But it does not work subsequently:
msg = iv + cipher.encrypt(txt)
cipher.decrypt(iv+msg)
What am I doing wrong?
import hashlib
from Crypto.Cipher import AES
from Crypto import Random
h = hashlib.new('sha256')
h.update('my key')
key = h.digest()
iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_CFB, iv)
txt = 'hello world'
# This is the part where I'm confused, because it seems like encrypt will output a different result every time, so how can I decrypt it?
msg = cipher.encrypt(txt)
msg = cipher.encrypt(txt)
# etc
# it works like I would expect the first time when decrypting, if I follow the example from pycrypto docs:
msg = iv + cipher.encrypt(txt)
cipher.decrypt(iv + msg)
# But it does not work subsequently:
msg = iv + cipher.encrypt(txt)
cipher.decrypt(iv+msg)
What am I doing wrong?