Block Encrypter Description

Block Encrypter is designed to make encrypting data in .NET / C# easier. The code in this library has been developed over the past year and used in my open source tools SafePad and Text Shredder. The way in which this library goes about encryption has been peer reviewed by many people in the open source community so you should feel rest assured it is a secure way to encrypt data using standard cryptographic primitives like AES, HMAC, PBKDF, and cryptographically secure random number generation.

encryption

First lets look at some usage examples. The main object in the library to call is the Block Encrypter object and this contains methods that allow you to encrypt/decrypt strings or byte arrays of data.

Encrypting and Decrypting Strings

 
 
 
 
 
 
const string originalMessage = "This is my message to encrypt.";
 
string encrypted = BlockEncrypter.EncryptStringBlock(originalMessage, Encoding.ASCII.GetBytes("Pa55w0rd"));
string decrypted = BlockEncrypter.DecryptStringBlock(encrypted, Encoding.ASCII.GetBytes("Pa55w0rd"));
 
Assert.AreEqual(originalMessage, decrypted);

In the example above the string “This is my message to encrypt” is encrypted and then decrypted using the password “Pa55w9rd”. Naturally this is a really bad password, but it is just an example.

Encrypting and Decrypting Byte Arrays

 
 
 
 
 
const string originalMessage = "This is my message to encrypt.";
byte[] testBytes = ByteHelpers.GetBytes(originalMessage);
 
byte[] encrypted = BlockEncrypter.EncryptByteBlock(testBytes, Encoding.ASCII.GetBytes("Pa55w0rd"));
byte[] decrypted = BlockEncrypter.DecryptByteBlock(encrypted, Encoding.ASCII.GetBytes("Pa55w0rd"));
 
Assert.IsTrue(ByteHelpers.ByteArrayCompare(testBytes, decrypted));

For more information about how Block Encrypter encrypts data, please read my article on it which goes into a bit more detail about the encryption process.

Last edited Apr 2, 2014 at 10:29 PM by stephenhaunts, version 6