Encrypter

A class to assist in Encrypting and Decrypting data.

Constructors

public class Encrypter

Methods

public string Encrypt(string valueToEncrypt)

Encrypt a value.

string valueToEncrypt

The string value to encyrpt.

public string Encrypt(string valueToEncrypt, byte[] key, byte[] iv)

Encrypt a value with passed in key and seed.

string valueToEncrypt

The string value to encyrpt.

byte[] key

The key to use to encrypt.

byte[] iv

The seed used in encrypting.

public string Decrypt(string encryptedValue)

Decrypt a value.

string encryptedValue

The string value to decyrpt.

public string Decrypt(string encryptedValue, byte[] key, byte[] iv)

Decrypt a value with passed in key and seed.

string encryptedValue

The string value to decyrpt.

byte[] key

The key to use to decyrpt.

byte[] iv

The seed used in decrypting.

public string ReEncrypt(string valueToReEncrypt, byte[] newKey, byte[] newIv)

Decrypt a value and then ReEncrypt the value with passed in key and seed.

string encryptedValue

The string value to decyrpt.

byte[] newKey

The key to use to encrypt.

byte[] newIv

The seed used in encrypting.

public string ReEncrypt(string valueToReEncrypt, byte[] newKey, byte[] newIv, byte[] oldKey, byte[] oldIv)

Decrypt a value and then ReEncrypt the value with passed in key and seed.

string encryptedValue

The string value to decyrpt.

byte[] newKey

The key to use to encrypt.

byte[] newIv

The seed used in encrypting.

byte[] oldKey

The key to use to decrypt.

byte[] oldIv

The seed used in decrypting.

public byte[] GenerateKey()

Randomly generate a new key to use with encrypting. This can be used with the Encrypt above without specifying a key.

public byte[] GenerateIV()

Randomly generate a new seed to use with encrypting. This can be used with the Encrypt above without specifying an iv.

public List<byte[]> SplitKey(byte[] key, int numberOfParts)

Split a key into a designated number of parts to be stored in different locations. This prevents key theft as all key parts are required to be able to recombine and use.

byte[] key

The key or iv value to split into a list of parts.

int numberOfParts

The number of byte arrays to create to from this key.

public byte[] CombineKeys(List<byte[]> keyParts)

Combine a list of split keys back into the orignal key value.

byte[] key

The list of split key or iv values to recombine again.

Example

C#
var enc = new Encrypter();
var key = enc.GenerateKey();
var iv = enc.GenerateIV();

var x = enc.Encrypt();