Skip to content

AESHMAC512 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

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 },
	}
};

To start using the DataTable extension functions add the following namespace.

using DotNetAES.Extensions;

AESHMAC512Encrypt

This function encrypts all the columns in a DataTable.

Syntax

DataTable AESHMAC512Encrypt(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

// Encrypts the DataTable and returns it
dt = dt.AESHMAC512Encrypt(AESHMAC512, cryptKey, authKey);

AESHMAC512EncryptIgnore

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

Syntax

DataTable AESHMAC512EncryptIgnore(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey, params string[] ignoreColumns)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

//Encrypts the DataTable and returns it
dt = dt.AESHMAC512EncryptIgnore(AESHMAC512, cryptKey, authKey, "column_two");

AESHMAC512EncryptOnly

This function encrypts only the specified columns in a DataTable.

Syntax

DataTable AESHMAC512EncryptOnly(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey, params string[] onlyColumns)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

//Encrypts the DataTable and returns it
dt = dt.AESHMAC512EncryptOnly(AESHMAC512, cryptKey, authKey, "column_two");

AESHMAC512Decrypt

This function decrypts all the columns in a DataTable.

Syntax

DataTable AESHMAC512Decrypt(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESHMAC512Decrypt(AESHMAC512, cryptKey, authKey);

AESHMAC512DecryptIgnore

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

Syntax

DataTable AESHMAC512DecryptIgnore(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey, params string[] ignoreColumns)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESDecryptIgnore(AESHMAC512, cryptKey, authKey, "column_two");

AESHMAC512DecryptOnly

This function decrypts only the specified columns in a DataTable.

Syntax

DataTable AESHMAC512DecryptOnly(this DataTable data, AESHMAC512 encryptionEngine, object cryptKey, object authKey, params string[] onlyColumns)

Example Usage

AESHMAC512  AESHMAC512  = new AESHMAC512 ();

// Generates a encryption key and the authentication key for the example
string cryptKey = AESHMAC512.CreateAESStringKey();
string authKey = AESHMAC512.CreateHMACAuthenticationStringKey();

//Decrypts the DataTable and returns it
dt = dt.AESHMAC512DecryptOnly(AESHMAC512, cryptKey, authKey, "column_two");