Net Encryption Library
RSA Encrypt Files
Basic Tasks > RSA Encrypt Files

RSA Encrypt Files Overview

RSA uses a concept of a public key and a private key.  Information is encrypted using the public key and then decrypted with the private key.

https://en.wikipedia.org/wiki/RSA_(cryptosystem)

When encrypting files and streams, a random key is created, encrypted, and inserted as a header.  The remainder of the stream is encrypted with the key using AES256.

 

C# Example

Encryption encryption = new Encryption(); //Trial Mode

//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode

 

string inputFilePath = "test.txt";

File.WriteAllText(inputFilePath,"This is a test");

string encrypted = "encrypted.txt";

string decrypted = "decrypted.txt";

 

AsymmetricKeyPair keys = encryption.GenerateRSAKeys();

 

bool isEncrypted = encryption.EncryptFile(EncryptionProvider.RSA, keys.PublicKeyOnly, inputFilePath, encrypted, false);

 

bool isDecrypted = encryption.DecryptFile(EncryptionProvider.RSA, keys.PublicPrivateKeyPair, encrypted, decrypted, false);

 

VB.NET Example

 

Dim encryption As New Encryption() 'Trial Mode

'Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode

  

Dim inputFilePath As String = "test.txt"

File.WriteAllText(inputFilePath,"This is a test")

Dim encrypted As String = "encrypted.txt"

Dim decrypted As String = "decrypted.txt"

  

Dim keys As AsymmetricKeyPair = encryption.GenerateRSAKeys()

  

Dim isEncrypted As Boolean = encryption.EncryptFile(EncryptionProvider.RSA, keys.PublicKeyOnly, inputFilePath, encrypted, False)

  

Dim isDecrypted As Boolean = encryption.DecryptFile(EncryptionProvider.RSA, keys.PublicPrivateKeyPair, encrypted, decrypted, False)