On 24.10.2013 09:33, Johannes Bauer wrote: > On 24.10.2013 07:22, Paul Pittlerson wrote: > >> What am I doing wrong? > > You're not reinitializing the internal state of the crypto engine. When > you recreate "cipher" with the same IV every time, it will work.
Code that works: #!/usr/bin/python3 import hashlib from Crypto.Cipher import AES from Crypto import Random h = hashlib.new('sha256') h.update(b'my key') key = h.digest() iv = Random.new().read(AES.block_size) cipher = AES.new(key, AES.MODE_CFB, iv) txt = 'hello world' msg = cipher.encrypt(txt) print(msg) cipher = AES.new(key, AES.MODE_CFB, iv) # Use *same* IV! origtxt = cipher.decrypt(msg) print(origtxt) Also note that manually deriving a symmetric secret using SHA256 is an INCREDIBLY bad idea. Have a look at PBKDF2. Best regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht öffentlich! Ah, der neueste und bis heute genialste Streich unsere großen Kosmologen: Die Geheim-Vorhersage. - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1...@speranza.aioe.org> -- https://mail.python.org/mailman/listinfo/python-list