Simple Example Aes256 Crypt
Why this example doesn't work ? from Crypto.Cipher import AES x = AES.new('sdsfdsafsadfdsafasdfdsarwe876539', AES.MODE_CBC, '2324234342342342') print x.decrypt(x.encrypt('abcdfghk
Solution 1:
Because x
is an object with state. Using it to encrypt a string changes the state; using it again will generate different output.
Use a new AES cipher with the same initial state as you had when encrypting:
>>> from Crypto.Cipher import AES
>>> key= "sdsfdsafsadfdsafasdfdsarwe876539"
>>> prefix= '2324234342342342'
>>> AES.new(key, AES.MODE_CBC, prefix).encrypt('abcdfghkbhgjrdfs')
'\xf4\xd9\xd1B8\xc1\x16\xe1\x9b~\xd0\x99\x1c\xf8\xdfn'
>>> AES.new(key, AES.MODE_CBC, prefix).decrypt(_)
'abcdfghkbhgjrdfs'
Post a Comment for "Simple Example Aes256 Crypt"