1

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 send to my Javascript Client wich 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."

Community
  • 1
  • 1
Jochen Kühner
  • 1,385
  • 2
  • 18
  • 43
  • Can System.Security.Cryptography.RSACryptoServiceProvider use a key size greater than 256? – ghangas Dec 10 '15 at 11:50
  • 1
    A 2048 bit key can be used to encrypt a max of 245 bytes, if the encryption works presumably your length is less than this, how is the data received by the back end? as base64/hex string? Are you transforming this back into a byte[] correctly? – Alex K. Dec 10 '15 at 11:55
  • Does JSEncrypt.encrypt returen something base64 encoded? I thought these are the encrypted bytes? – Jochen Kühner Dec 10 '15 at 12:55
  • I looked and yes it returns Base64 so you need to convert that to a byte array for decryption – Alex K. Dec 10 '15 at 13:49
  • So the question becomes to Jochen: did you decode the data before decrypting it? If not then Alex may have answered your question – Maarten Bodewes Dec 10 '15 at 20:02
  • I now tried to use atob(xx) of the encrypted data, before I send it over the websocket! But I still get the same error on the backend! – Jochen Kühner Dec 11 '15 at 07:20

1 Answers1

1

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#

Community
  • 1
  • 1
Jochen Kühner
  • 1,385
  • 2
  • 18
  • 43