how to use RSA to encrypt files (huge data) in C#

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

  1. Generate a random key of the correct length required for AES (or similar).
  2. Encrypt your data using AES or similar using that key
  3. Encrypt the random key using your RSA key

Then you publish both the outputs from 2 and 3

To decrypt

  1. Decrypt the AES key using your RSA key.
  2. Decrypt the data using that AES key

Leave a Comment