Walker.Crypto.SimpleAESEncryption
Provides simple, sync-based AES-GCM encryption and decryption with a key derived from a password. Includes helpers for secure key generation and basic parsing.
Types
AESEncryptedText
Holds AES-GCM encrypted data and its associated IV.
-
Fields:
- string IV: Base64-encoded initialization vector.
- string EncryptedText: Base64-encoded ciphertext.
-
Methods:
- string ToString(): Converts the data to a string using the format IV|EncryptedText.
- static AESEncryptedText FromUTF8String(string input): Parses a string in the IV|EncryptedText format. Throws FormatException if the input is invalid.
Methods
Encrypt(string plainText, SecureData password)
Encrypts plain text using AES-GCM. Outputs both the encrypted content and IV.
-
Parameters:
- plainText: Text to encrypt.
- password: Used to derive a 256-bit key.
-
Returns: AESEncryptedText
Decrypt(AESEncryptedText encrypted, SecureData password)
Decrypts a previously encrypted value using its IV and the original password. Returns a secure string.
-
Parameters:
- encrypted: The encrypted payload and IV.
- password: Used to derive the decryption key.
-
Returns: SecureData
Decrypt(string encryptedText, string ivBase64, SecureData password)
Takes the raw Base64 ciphertext and IV, decrypts it using the password, and returns the plain string.
-
Parameters:
- encryptedText: Base64 string of the ciphertext.
- ivBase64: Base64 IV.
- password: The password to derive the key.
-
Returns: string
GenerateRandomBytes(int size)
Creates a secure random byte array of the given size.
-
Parameters:
- size: How many bytes to generate.
-
Returns: byte[]
DeriveKey(SecureData password, int keyBytes)
Hashes the password with SHA-256 and adjusts the result to the specified byte length.
-
Parameters:
- password: The password to derive from.
- keyBytes: The size of the final key in bytes.
-
Returns: byte[]