Sign in to follow this  
Followers 0
sathenzar

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

2 posts in this topic

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.