[pycrypto] AES.Mode_PGP

David Arena arenstar at gmail.com
Mon Feb 14 13:48:03 CST 2011

Hello All..

basically im either stupid or guessing something is wrong with the Mode_PGP of the Cipher AES class..

Let me explain..

I assumed that the class would follow the rfc 2440 ( OpenPGP Message Format)
Basically, in my laymans terms..

On encryption...
The IV is a random generated number, added  as the first block of the ciphertext and used in CBC mode for the other blocks...

On Decryption..
The IV added is zero's, The CBC continues finding the IV in the first block, which results in the following blocks to be deciphered correctly.. However  when returning the plaintext it drops the first block of the plaintext  garbage..
resulting in a correct message..

Im not sure if Pycrypto does this??? I tried and failed.. and i thought i should ask questions..

here is my basic code..

 def AESencode(secretkey,message,vi):
                cipher = AES.new(secretkey,AES.MODE_PGP,vi)
                return cipher.encrypt(base64.b64encode(message))

 def AESdecode(secretkey,message):
                cipher = AES.new(secretkey,AES.MODE_PGP)
                return cipher.decrypt(base64.b64decode(message))

Any suggestions on where to go????


More information about the pycrypto mailing list