This library combines the .NET built-in AES and HMAC algorithms to provide an easy-to-use interface for doing authenticated encryption. The library is based on this Gist by James Tuley: https://gist.github.com/jbtule/4336842, but modified slightly to only support the key based versions. Also it does not use the GCM version currently, so there are no external dependencies.
Install via NuGet:
Install-Package AuthenticatedEncryption
The library consists of a single static class. This makes it very easy to use. It uses Authenticated Encryption with Associated Data (AEAD), using the approach called “Encrypt then MAC” (EtM). It uses one key for the encryption part (cryptkey) and another key for the MAC part (authkey).
This is a simple example of encrypting and decrypting some string:
using AuthenticatedEncryption;
const string Input = "this is a test input string";
var cryptKey = Encryption.NewKey();
var authKey = Encryption.NewKey();
var cipherText = Encryption.Encrypt(Input, cryptKey, authKey);
var plainText = Encryption.Decrypt(cipherText, cryptKey, authKey);