[pycrypto] RSA / OAEP - ValueError: Plaintext is too long.

Antonio Teixeira eagle.antonio at gmail.com
Wed Apr 11 05:25:05 EDT 2012


Good Morning.

I'm in a no way a crypto expert just trying to encrypt some traffic inside
our cluster between machines :) so be nice :D

Anyway , I currently have the following code :

self.publicKey = RSA.importKey(str(b64decode(publicKey)))
encryptCipher = PKCS1_OAEP.new(self.publicKey)
Data = encryptCipher.encrypt(Data)

This Raises The Exception ValueError: Plaintext is too long.

This is An Example Payload
{"ACTION": "CLASSIFIED", "TASK": "HELLO", "PAYLOAD": "{\"TIME\": 10}",
"TASK_ID": "c38aac1a-03ea-492d-9c03-27d9ea29eb0d"}

So after a small search i found out that if i increase the RSA Modulus i'm
able to encrypt larger number of bits ( makes sense )  but this feels dirty.

What do your guys recommend ?

Breaking the data in chunks and encrypting part by part joining it all in a
buffer and send it down the socket all in one with the other server
decrypting part by part and merging the data again ?

P.S - I dont mind fishing by myself just trying to understand the best "way
/ more correct way " to do it :)

Regards
Antonio Teixeira
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dlitz.net/pipermail/pycrypto/attachments/20120411/a7793764/attachment.html>


More information about the pycrypto mailing list