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.
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?
With the current block encrypter, both ends would need the same password. You can use RSA to encrypt this password and use private / public keys. as you mention, but its not built into the block encryper.
It is easy to do though. I wrote an article on how to do this here:
https://stephenhaunts.com/2013/05/18/cryptography-in-net-hybrid-encryption-protocols/