Encrypt and Decrypt a File Using an X509 Certificate from Your Store

This sample demonstrates how to use an X509 certificate from your certificate file to encrypt a file, and how a recipient can use the same certificate in their store to deccrypt the file.

C# (59.7 KB)
3,096 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • modulus exceeded
    2 Posts | Last post September 22, 2016
    • I have been working with your sample code you provided and testing out how it works, but I am running into an issue.  I seem to be able to encrypt the file just fine, but when I try to decrypt the file it throws an error stating that the decrypted data exceeds the maximum for this modulus of 256 bytes.  I am using a X509 cert that is 2048 bit.  The file that I am trying to encrypt is 1Kb, but I would like to be able handle files up to 1Mb.
      Do you have any suggestions on what might resolve this?
    • For large files, encrypt using symmetric encryption.  Then, encrypt the symmetric key using the certificate.