Skip to content

CryptoUtils ​

Namespace: MJCZone.DapperMatic.AspNetCore.Security

Assembly: MJCZone.DapperMatic.AspNetCore

Summary ​

Utility methods for encryption and decryption using AES-GCM. Supports both raw 256-bit keys (Base64) and passphrase-derived keys (PBKDF2). Encrypted payloads include necessary metadata (mode, salt, nonce, tag).

static public

Contents ​

Methods (9)

Methods ​

MethodSummary
GenerateEncryptionKeyGenerates a random 256-bit key, returned as Base64. Store this securely (e.g., in a secrets manager ...
EncryptToBase64Encrypts UTF-8 text and returns ciphertext as Base64.
DecryptFromBase64Decrypts Base64 ciphertext into UTF-8 text.
EncryptEncrypts raw bytes and returns ciphertext bytes.
DecryptDecrypts raw ciphertext bytes produced by String)....
GetType
ToString
Equals
GetHashCode

GenerateEncryptionKey ​

Generates a random 256-bit key, returned as Base64. Store this securely (e.g., in a secrets manager or KMS).

csharp
string GenerateEncryptionKey()

Returns ​

Type: string

A Base64-encoded 256-bit encryption key.

EncryptToBase64 ​

Encrypts UTF-8 text and returns ciphertext as Base64.

csharp
string EncryptToBase64(string plaintext, string encryptionKey)

Parameters ​

  • plaintext (string) - The plain text to encrypt.
  • encryptionKey (string) - The encryption key (Base64 32-byte or passphrase).

Returns ​

Type: string

The encrypted text as Base64.

DecryptFromBase64 ​

Decrypts Base64 ciphertext into UTF-8 text.

csharp
string DecryptFromBase64(string ciphertextBase64, string encryptionKey)

Parameters ​

  • ciphertextBase64 (string) - The encrypted text as Base64.
  • encryptionKey (string) - The encryption key (Base64 32-byte or passphrase).

Returns ​

Type: string

The decrypted plain text.

Encrypt ​

Encrypts raw bytes and returns ciphertext bytes.

csharp
Encrypt(Byte[] plaintext, string encryptionKey)

Parameters ​

  • plaintext (Byte[]) - The plain text bytes to encrypt.
  • encryptionKey (string) - The encryption key (Base64 32-byte or passphrase).

Returns ​

The encrypted bytes.

Decrypt ​

Decrypts raw ciphertext bytes produced by String).

csharp
Decrypt(Byte[] payload, string encryptionKey)

Parameters ​

  • payload (Byte[]) - The encrypted bytes.
  • encryptionKey (string) - The encryption key (Base64 32-byte or passphrase).

Returns ​

The decrypted plain text bytes.

GetType ​

csharp
GetType()

ToString ​

csharp
ToString()

Equals ​

csharp
Equals()

GetHashCode ​

csharp
GetHashCode()