• 0

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


Question

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.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

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.com/questions/1199058/how-to-use-rsa-to-encrypt-files-huge-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

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.