Python Crytographic Toolkit, AES and OpenPGP

ml1n emlyn at brizzle.com
Tue Oct 24 07:28:56 EDT 2006


Hello,
Does anybody have an example of using Crypto.Cipher.AES to encrypt an
OpenPGP literal data packet?  I can't get MODE_PGP to work at all (gpg
doesn't recognise the unencrypted packet), with MODE_CFB gpg correctly
identifies the packet after decryption but it's body is incorrect
(suggesting the first 2 bytes decrypt/encrypt ok but the rest
doesn't?). I know the plain text version of the packet is ok because I
can add it to the stream without encryption and gpg will process it ok.

Here is what I'm trying (text is the pre constructed packet):

aes_obj =
Crypto.Cipher.AES.new(self.sessionKey,Crypto.Cipher.AES.MODE_CFB,"\x00"*16)
padding = self.randPool.get_bytes(Crypto.Cipher.AES.block_size)
padding = "%s%s" % (padding,padding[-2:])
self.enc_text = aes_obj.encrypt("%s%s" % (padding,text))

I'm sure I'm missing something obvious, Any pointers gratefully
recieved.

Thanks.
M.




More information about the Python-list mailing list