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.



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.


  1. If I have 2 servers communicating through whatever transport I choose (which is irrelevant to the current question), would I have to code the password used by both to be the same? Or can I somehow get a private/public key thing going somehow, so that both servers have public keys that server 1 can communicate with server 2, and both have unique private keys as well?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: