Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit 8e5ad80 Mar 31, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.nuget Initial version of the Simple AES library Jun 16, 2014
sample
src
tests/Test.SimpleAesEncryption
.gitattributes Initial version of the Simple AES library Jun 16, 2014
.gitignore Initial version of the Simple AES library Jun 16, 2014
LICENSE Initial commit Jun 16, 2014
README.md
SimpleAesEncryption.sln Added sample projects and updated readme Jun 18, 2014

README.md

Simple Aes Encryption

This library lets you encrypt string based messages using the standard AES symmetric key encryption algorithm (Rijndael).

Installation

The simple AES encryption library can be downloaded and installed from NuGet: http://www.nuget.org/packages/Simple.AES/

Configuration

Once the NuGet package has been installed, all that is required to use the tool is a few configuration changes.

1) Add the SimpleAesEncryptionConfiguration configuration sections

In order to let .NET know that there are some custom configuration settings that can be accessed, you need to update the configSections portion of the configuration file with the following:

<configsections>
   <section name="MessageEncryption" type="ArtisanCode.SimpleAesEncryption.SimpleAesEncryptionConfiguration, ArtisanCode.SimpleAesEncryption"/>
  <!-- Additional sections may be defined but not duplicated -->
</configsections>

2) Add encryption configuration

This is the heart of the library, this tells the encryption algorithm everything it needs in order to function correctly.

<MessageEncryption>
  <EncryptionKey KeySize="256" Key="3q2+796tvu/erb7v3q2+796tvu/erb7v3q2+796tvu8="/>
</MessageEncryption>

Important

  • The recommended KeySize value is 256 (the maximum permitted). This represents the length in bits of the encryption key. The encryption key must be exactly this length.
  • Please do not use this example key ... EVER!! Please ensure that you generate a new encryption key in a safe and secure manner. You can find a helper program within the sample folder called KeyGen that is able to create a new symmetric key for the MessageEncryptor.

Generate the key by either:

  1. Building and running the KeyGen program
  2. Running this code:
    var cryptoContainer = new RijndaelManaged {KeySize = 256};//use your own keysize
                cryptoContainer.GenerateKey();
                var key = Convert.ToBase64String(cryptoContainer.Key);
  3. Using the following powershell snippet to generate the key:
    $container = New-Object System.Security.Cryptography.RijndaelManaged
    # defaults
    # $container.KeySize = 256
    # $container.Mode = CBC
    [Convert]::ToBase64String($container.Key)
  • This key is the same key used to encrypt and decrypt so if this gets compromised then you will need to re-encrypt everything that was encrypted with the compromised key. To help keep this encryption information more secure, it is highly recommended that you encrypt the <Log4NetMessageEncryption>...</Log4NetMessageEncryption> configuration section using a tool like Aspnet_regiis

Usage

There are only two interfaces that this library exposes:

These interfaces only expose one function each:

string Encrypt(string source);
string Decrypt(string cypherText);

You can create instances of RijndaelMessageEncryptor and RijndaelMessageDecryptor directly by using the relevent constructors OR, you can use your favourite Dependency Injection container to manage the instansiation for you.

For an idea of how to use this library, please refer to the sample projects:

  • Simple Example - shows how to use the library in its simplest form
  • Integration with Castle whilst using a custom configuration section name to contain the encryption information

That's all you need to know in order to start encrypting and decrypting to your heart's content!

You can’t perform that action at this time.