ArgumentError: message representative out of range when using the rsa gem

Go To StackoverFlow.com

0

I am getting this error when trying to encrypt big messages. I wonder whether this is a limitation with rsa.rb or if I am doing something wrong. Did anyone bump against this error?

This is happening on the client side, where I am encrypting a huge message using the server's public key like this:

RSA::KeyPair.new(nil,server_public_key).encrypt(huge_base64_str)

This code blows up with the ArgumentError: message representative out of range when using the rsa gem

2012-04-05 16:47
by Pedro Morte Rolo
Can you show your code - Guilherme Bernal 2012-04-05 17:02
can you upvote my question now - Pedro Morte Rolo 2012-04-05 17:25
Why should I upvote your question - Guilherme Bernal 2012-04-05 19:45
Well, because it is well formed and because I need help... Whatever.. - Pedro Morte Rolo 2012-04-05 21:06
Using RSA to encrypt data is usually the wrong thing to do. With the most common padding scheme your data is required to be <= n - 11 bytes in length, where n is the length of the RSA modulus in bytes - James K Polk 2012-04-05 21:57
GregS: So what alternatives do I have, considering that using public key cryptography is a requirement - Pedro Morte Rolo 2012-04-06 10:06


0

The best thing to do in this case is to encrypt the message with a symetric key (e.g. AES) and then encrypt the symetric key with rsa. and send the message and the encrypted symetric key.

2012-04-06 14:05
by Pedro Morte Rolo
Ads