CryptoUtils
Namespace: MJCZone.MediaMatic.AspNetCore.Security
Assembly: MJCZone.MediaMatic.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
| Method | Summary |
|---|---|
| GenerateEncryptionKey | Generates a random 256-bit key, returned as Base64. Store this securely (e.g., in a secrets manager ... |
| EncryptToBase64 | Encrypts UTF-8 text and returns ciphertext as Base64. |
| DecryptFromBase64 | Decrypts Base64 ciphertext into UTF-8 text. |
| Encrypt | Encrypts raw bytes and returns ciphertext bytes. |
| Decrypt | Decrypts 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).
string GenerateEncryptionKey()Returns
Type: string
A Base64-encoded 256-bit encryption key.
EncryptToBase64
Encrypts UTF-8 text and returns ciphertext as Base64.
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.
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.
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).
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
GetType()ToString
ToString()Equals
Equals()GetHashCode
GetHashCode()