EasyEncrypt 1.0.3.1

Library that makes encrypting strings, byte arrays and files easy. Supports Aes, TripleDES, (.net framework only) Des, RC2 and Rijndael. EasyEncrypt has a good documentation.

There is a newer version of this package available.
See the version list below for details.
Install-Package EasyEncrypt -Version 1.0.3.1
dotnet add package EasyEncrypt --version 1.0.3.1
<PackageReference Include="EasyEncrypt" Version="1.0.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyEncrypt --version 1.0.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Getting started

Example of encrypting a string or byte[] with Aes encryption:

string encryptedString = new Encryption(Aes.Create(), Password, Salt).Encrypt(Input);//1
string encryptedString = new Encryption(Aes.Create(), Keysize, Password, Salt).Encrypt(Input);//2

//Doesn't work with a byte[]
string EncryptedString = new Encryption(Aes.Create(), Password, Salt).Encrypt(Input, Encoding.Unicode);//3

Password is the password used to create the key.

Salt is used for making the generated key more random.

Keysize is the size of the key in bits. Example 1 takes the keysize for the algorithm.
In example 3 we use Unicode for decoding the string instead of UTF8(Default).

Example of decrypting a string or byte[] with Aes encryption:

string decryptedString = new Encryption(Aes.Create(), Password, Salt).Decrypt(EncryptedInput);//1
string decryptedString = new Encryption(Aes.Create(), Keysize, Password, Salt).Decrypt(EncryptedInput);//2

//Doesn't work with a byte[]
string decryptedString = new Encryption(Aes.Create(), Password, Salt).Decrypt(EncryptedInput, Encoding.Unicode);//3

When decrypting, the Password Salt and Keysize need to be the same for generating the same key.

More advanced

Encrypting with an already created key:

Encryption easyEncryption = new Encryption(Aes.Create(), Encryption.CreateKey(Keysize, Password, Salt));
Encryption easyEncryption = new Encryption(Aes.Create(), Encryption.CreateKey(Algorithm, Password, Salt));

Example of encrypting/decrypting with the other algorithms:

encryptedString = new Encryption(TripleDES.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(TripleDES.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(DES.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(DES.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(RC2.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(RC2.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(Rijndael.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(Rijndael.Create(), Password, Salt).Decrypt(EnryptedInput);

Encrypting with an already configured algorithm:

SymmetricAlgorithm algorithm = Aes.Create();
algorithm.Key = Encryption.CreateKey(algorithm,Password,Salt);
Encryption easyEncryption = new Encryption(algorithm);

encryptedString = easyEncryption.Encrypt(Input);
decryptedString = easyEncryption.Decrypt(EncryptedInput);

File encryption.

The fileEncryption class constructors are the same as the constructors for the Encryption class.

Example of encrypting and decrypting a file:

FileEncryption easyEncryption = new FileEncryption(Aes.Create(),PASSWORD,SALT);
easyEncryption.Encrypt(InputFile1,OutputFile1);
easyEncryption.Decrypt(InputFile2, OutputFile2);

InputFile1 is the location of the file to encrypt.
OutputFile1 is the location where to save the encrypted file.

InputFile2 is the location of the encrypted file.
OutputFile2 is the location where to save the decrypted file.

Overloads of all functions

Overloads of the constructor:

Encryption(SymmetricAlgorithm algorithm)
Encryption(SymmetricAlgorithm algorithm, byte[] key)
Encryption(SymmetricAlgorithm algorithm, string password, string salt, int iterations = 10000)
Encryption(SymmetricAlgorithm algorithm, int keySize, string password, string salt, int iterations = 10000)

Overloads of the CreateKey method(NOTE, THIS METHOD IS STATIC):

static byte[] CreateKey(int keySize, string password, string salt, int iterations = 10000)
static byte[] CreateKey(SymmetricAlgorithm algorithm, string password, string salt, int iterations = 10000)

Overloads of the Encryption functions:

string Encrypt(string text)
string Encrypt(string text, Encoding encoder)
byte[] Encrypt(byte[] data)

string Decrypt(string text)
string Decrypt(string text, Encoding encoder)
byte[] Decrypt(byte[] data)

byte[] GetKey()

Overloads of the FileEncryption functions:

Encrypt(string inputFile, string outputFile, int bufferSize = 1048576)
Decrypt(string inputFile, string outputFile, int bufferSize = 1048576)

byte[] GetKey()

Getting started

Example of encrypting a string or byte[] with Aes encryption:

string encryptedString = new Encryption(Aes.Create(), Password, Salt).Encrypt(Input);//1
string encryptedString = new Encryption(Aes.Create(), Keysize, Password, Salt).Encrypt(Input);//2

//Doesn't work with a byte[]
string EncryptedString = new Encryption(Aes.Create(), Password, Salt).Encrypt(Input, Encoding.Unicode);//3

Password is the password used to create the key.

Salt is used for making the generated key more random.

Keysize is the size of the key in bits. Example 1 takes the keysize for the algorithm.
In example 3 we use Unicode for decoding the string instead of UTF8(Default).

Example of decrypting a string or byte[] with Aes encryption:

string decryptedString = new Encryption(Aes.Create(), Password, Salt).Decrypt(EncryptedInput);//1
string decryptedString = new Encryption(Aes.Create(), Keysize, Password, Salt).Decrypt(EncryptedInput);//2

//Doesn't work with a byte[]
string decryptedString = new Encryption(Aes.Create(), Password, Salt).Decrypt(EncryptedInput, Encoding.Unicode);//3

When decrypting, the Password Salt and Keysize need to be the same for generating the same key.

More advanced

Encrypting with an already created key:

Encryption easyEncryption = new Encryption(Aes.Create(), Encryption.CreateKey(Keysize, Password, Salt));
Encryption easyEncryption = new Encryption(Aes.Create(), Encryption.CreateKey(Algorithm, Password, Salt));

Example of encrypting/decrypting with the other algorithms:

encryptedString = new Encryption(TripleDES.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(TripleDES.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(DES.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(DES.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(RC2.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(RC2.Create(), Password, Salt).Decrypt(EnryptedInput);

encryptedString = new Encryption(Rijndael.Create(), Password, Salt).Encrypt(Input);
decryptedString = new Encryption(Rijndael.Create(), Password, Salt).Decrypt(EnryptedInput);

Encrypting with an already configured algorithm:

SymmetricAlgorithm algorithm = Aes.Create();
algorithm.Key = Encryption.CreateKey(algorithm,Password,Salt);
Encryption easyEncryption = new Encryption(algorithm);

encryptedString = easyEncryption.Encrypt(Input);
decryptedString = easyEncryption.Decrypt(EncryptedInput);

File encryption.

The fileEncryption class constructors are the same as the constructors for the Encryption class.

Example of encrypting and decrypting a file:

FileEncryption easyEncryption = new FileEncryption(Aes.Create(),PASSWORD,SALT);
easyEncryption.Encrypt(InputFile1,OutputFile1);
easyEncryption.Decrypt(InputFile2, OutputFile2);

InputFile1 is the location of the file to encrypt.
OutputFile1 is the location where to save the encrypted file.

InputFile2 is the location of the encrypted file.
OutputFile2 is the location where to save the decrypted file.

Overloads of all functions

Overloads of the constructor:

Encryption(SymmetricAlgorithm algorithm)
Encryption(SymmetricAlgorithm algorithm, byte[] key)
Encryption(SymmetricAlgorithm algorithm, string password, string salt, int iterations = 10000)
Encryption(SymmetricAlgorithm algorithm, int keySize, string password, string salt, int iterations = 10000)

Overloads of the CreateKey method(NOTE, THIS METHOD IS STATIC):

static byte[] CreateKey(int keySize, string password, string salt, int iterations = 10000)
static byte[] CreateKey(SymmetricAlgorithm algorithm, string password, string salt, int iterations = 10000)

Overloads of the Encryption functions:

string Encrypt(string text)
string Encrypt(string text, Encoding encoder)
byte[] Encrypt(byte[] data)

string Decrypt(string text)
string Decrypt(string text, Encoding encoder)
byte[] Decrypt(byte[] data)

byte[] GetKey()

Overloads of the FileEncryption functions:

Encrypt(string inputFile, string outputFile, int bufferSize = 1048576)
Decrypt(string inputFile, string outputFile, int bufferSize = 1048576)

byte[] GetKey()

Release Notes

- Added GetKey()
Which returns the current encryption key.

  • .NETStandard 2.0

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.3.2 79 5/24/2019
1.0.3.1 112 4/11/2019
1.0.3 96 3/27/2019
1.0.2 109 2/16/2019
1.0.1.3 94 2/15/2019
1.0.1.2 98 2/15/2019
1.0.1.1 90 2/14/2019
1.0.1 103 2/12/2019