Table of Contents

Class AesEncryptionHelper

Namespace
NuvTools.Security.Helpers
Assembly
NuvTools.Security.dll

Provides helper methods for AES symmetric encryption and decryption. The encryption format is AES-CBC with the layout IV (16 bytes) + ciphertext, using a SHA-256-derived key.

public static class AesEncryptionHelper
Inheritance
AesEncryptionHelper
Inherited Members

Methods

DecryptAES128(byte[], string)

Decrypts a byte array encrypted with AES-128 and returns the original plain text.

public static string DecryptAES128(byte[] cipherData, string key)

Parameters

cipherData byte[]
key string

Returns

string

DecryptAES192(byte[], string)

Decrypts a byte array encrypted with AES-192 and returns the original plain text.

public static string DecryptAES192(byte[] cipherData, string key)

Parameters

cipherData byte[]
key string

Returns

string

DecryptAES256(byte[], string)

Decrypts a byte array encrypted with AES-256 and returns the original plain text.

public static string DecryptAES256(byte[] cipherData, string key)

Parameters

cipherData byte[]
key string

Returns

string

DecryptToBytes(byte[], string, SymmetricAlgorithmType)

Decrypts a byte array and returns the original plain bytes (without UTF-8 conversion).

public static byte[] DecryptToBytes(byte[] cipherData, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

cipherData byte[]
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

byte[]

DecryptToBytes(string, string, SymmetricAlgorithmType)

Decrypts a Base64 string and returns the original plain bytes (without UTF-8 conversion).

public static byte[] DecryptToBytes(string cipherText, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

cipherText string
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

byte[]

DecryptToString(byte[], string, SymmetricAlgorithmType)

Decrypts a byte array and returns the original plain text. Throws if the payload is malformed (caller is responsible for validation or fallback handling).

public static string DecryptToString(byte[] cipherData, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

cipherData byte[]
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

string

DecryptToString(string, string, SymmetricAlgorithmType)

Decrypts a Base64 string and returns the original plain text. If the input is not a valid Base64 string or cannot be decrypted, the value is returned as-is (fallback for legacy plain-text data).

public static string DecryptToString(string cipherText, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

cipherText string
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

string

EncryptAES128(string, string)

Encrypts a string using AES-128 and returns the result as a byte array.

public static byte[] EncryptAES128(string plainText, string key)

Parameters

plainText string
key string

Returns

byte[]

EncryptAES192(string, string)

Encrypts a string using AES-192 and returns the result as a byte array.

public static byte[] EncryptAES192(string plainText, string key)

Parameters

plainText string
key string

Returns

byte[]

EncryptAES256(string, string)

Encrypts a string using AES-256 and returns the result as a byte array.

public static byte[] EncryptAES256(string plainText, string key)

Parameters

plainText string
key string

Returns

byte[]

EncryptToBytes(string, string, SymmetricAlgorithmType)

Encrypts a string and returns the result as a byte array. Format: IV (16 bytes) + ciphertext.

public static byte[] EncryptToBytes(string plainText, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

plainText string
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

byte[]

EncryptToString(string, string, SymmetricAlgorithmType)

Encrypts a string and returns the result as a Base64 string.

public static string EncryptToString(string plainText, string key, AesEncryptionHelper.SymmetricAlgorithmType algorithm = SymmetricAlgorithmType.AES256)

Parameters

plainText string
key string
algorithm AesEncryptionHelper.SymmetricAlgorithmType

Returns

string