Jump to content



Photo

[C#] RSA not able to take special characters or new lines?


  • Please log in to reply
1 reply to this topic

#1 sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 17 September 2012 - 03:23

I have been programming for a bit in C# but never messed with RSA encryption before. I can encrypt/decrypt a standard string easily. However if I ever read in a text file (by using a filestream.read into a buffer) I can never get it to encrypt right or at all. It'll either return the encrypted bytes as null or if it does return it'll come back as a bunch of question marks when I decrypt it.


#2 OP sathenzar

sathenzar

    Neowinian

  • Joined: 12-June 06

Posted 17 September 2012 - 03:29

Ah, I answered my own question while reading more into it on various sites, it's not made for what I'm doing :) Sorry everyone. But the practices still if anyone has advice would be nice on using RSA for keys and then I guess you can encrypt still using AES/RSA together? Siting this page: http://stackoverflow...data-in-c-sharp


RSA can only encrypt data blocks that are shorter than the key length so what you normally do is

  • Generate a random key of the lnght required for AES or similar.
  • Encrypt your data using AES or similar using that key
  • Encrypt the random key using your RSA key

Then you publish both the outputs from 2 and 3

To decrypt
  • Decrypt the AES key using your RSA key.
  • Decrypt the data using that AES key





Click here to login or here to register to remove this ad, it's free!