javascriptc#encryptioncryptography

encrypt data in Javascript with "RSACryptoServiceProvider" Public Key -> Exceed Maximum Exception


I have a Instance of the "RSACryptoServiceProvider" in my backend Code.

  oRsa = new System.Security.Cryptography.RSACryptoServiceProvider(2048);
  var Key = CryptoHelper.ExportPublicKey(oRsa);

The Code to Export the Public Key I got from here: https://stackoverflow.com/a/28407693/579623 ( I also tried this https://stackoverflow.com/a/25591659/579623)

the "key" is sent to my JavaScript Client which uses JSEncrypt to encrypt the Data.

Problem now is I got the following error in my Backend:

"The data to be decrypted exceeds the maximum for this modulus of 256 bytes."


Solution

  • I finaly got it to working using Code from : http://www.codeproject.com/Articles/22073/Object-Oriented-JavaScript-Class-Library-in-C-NET it was sugested here: RSA: Encrypt password in javascript but failed to decrypt that in C#