Possible Duplicate:
RSA Encryption, getting bad length
I am trying to encrypt a large string using RSA. .NET’s default implementation lets me encrypt easily small strings, but when I pass large one it throws a CryptographyException: Bad length.
I would like to overcome this, but the problem is that I need to pass the encypted string to another application which I cannot modify (because it’s not mine 😉
So is there an RSA implementation which I can use to load X509 Public Key and then encrypt large strings?
Thank you
You will need to contrive something in order to accomplish this, perhaps by splitting it into blocks and encrypting each block.
It’s not working because the plaintext length in RSA encryption is limited by the length of the key, i.e. it is impossible to encrypt a piece of data larger than the key used to encrypt it. Generally, a one-off exchange of a symmetric key is performed with RSA, and an agreed-upon symmetric algorithm is used from there.
Also, RSA is (compared to symmetric algorithms) very computationally expensive and breaking large data into many dozens (perhaps hundreds?) of small blocks would suffer terrible performance problems, you’d probably only be able to encrypt a few megabytes per second.
Strongly consider an alternate approach.
Edit: Also, consult the documentation of the program that must accept these encrypted strings, because it doesn’t help you to use some nonstandard way of encrypting them if the program will be unable to decrypt them.