Skip to content

AES DataTable Extension

David Whitehead edited this page May 4, 2019 · 1 revision

Getting Started

To start using the DataTable extension functions add the NuGet package or reference the DLL file in your solution.

then add the following namespace.

using DotNetAES.Extensions;

DataTable Extension Functions

NOTE: All DataTable encryption extension functions populate the iv column with a randomly generated IV per row.

The following DataTable will be used in all examples below.

DataTable dt = new DataTable()
{
	Columns =
	{
		"column_one","column_two", "column_three", "column_four", "column_five", "column_iv",
	},
	Rows =
	{
		{ "one", "two", "three", "four", "five" },
		{ "one2", "two2", "three2", "four2", "five2" },
		{ "3one", "t3wo", "three3", "four3", "five3" },
		{ 2, 3, 4, 5, 6 },
		{ DateTime.Now, 2, 3 },
	}
};

AESEncrypt

This function encrypts all the columns in a DataTable except the IV column.

Syntax

DataTable AESEncrypt(this DataTable data, AES encryptionEngine, string ivColumnName, object key)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Encrypts the DataTable and returns it
dt = dt.AESEncrypt(AES, "column_iv", key);

AESEncryptIgnore

This function encrypts all the columns in a DataTable except the IV column and all column names in the ignore list.

Syntax

DataTable AESEncryptIgnore(this DataTable data, AES encryptionEngine, string ivColumnName, object key, params string[] ignoreColumns)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Encrypts the DataTable and returns it
dt = dt.AESEncryptIgnore(AES, "column_iv", key, "column_two");

AESEncryptOnly

This function encrypts only the specified columns in a DataTable using the IV column.

Syntax

DataTable AESEncryptOnly(this DataTable data, AES encryptionEngine, string ivColumnName, object key, params string[] onlyColumns)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Encrypts the DataTable and returns it
dt = dt.AESEncryptOnly(AES, "column_iv", key, "column_two");

AESDecrypt

This function decrypts all the columns in a DataTable except the IV column.

Syntax

DataTable AESDecrypt(this DataTable data, AES encryptionEngine, string ivColumnName, object key)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESDecrypt(AES, "column_iv", key);

AESDecryptIgnore

This function decrypts all the columns in a DataTable except the iv column and all column names in the ignore list.

Syntax

DataTable AESDecryptIgnore(this DataTable data, AES encryptionEngine, string ivColumnName, object key, params string[] ignoreColumns)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESDecryptIgnore(AES, "column_iv", key, "column_two");

AESDecryptOnly

This function decrypts only the specified columns in a DataTable using the IV column.

Syntax

DataTable AESDecryptOnly(this DataTable data, AES encryptionEngine, string ivColumnName, object key, params string[] onlyColumns)

Example Usage

AES AES = new AES();

//Generates a key for the example
string key = AES.CreateAESStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESDecryptOnly(AES, "column_iv", key, "column_two");