Aes256GCMEncryptor

Aes256GCMEncryptor is a cryptographic utility for performing AES-256 encryption and decryption in GCM (Galois/Counter Mode). This class implements the Encryption interface and provides methods to securely encrypt and decrypt text data.

The class uses a specified secret key for encryption and decryption operations, ensuring that the integrity and confidentiality of the data are maintained. Nonces are generated randomly to ensure uniqueness and mitigate the risk of ciphertext reuse attacks.

Key features:

  • Secure AES-256-GCM encryption and decryption implementation

  • Random nonce generation for each encryption operation

  • Base64 encoding/decoding for easy integration with external systems

  • Implements platform-independent Encryption interface

Parameters

secretKey

A Base64-encoded string representing the AES-256 secret key to initialize the encryptor.

Throws

if the provided secret key is invalid or does not meet the required size.

Constructors

Link copied to clipboard
constructor(secretKey: String)

Creates an instance of Aes256GCMEncryptor using the provided secret key. The secret key must be a Base64-encoded string representing a valid 256-bit AES key.

Types

Link copied to clipboard
object Companion

Companion object for the Aes256GCMEncryptor class. Provides utility methods for managing AES-256-GCM encryption keys, including generation, serialization, and deserialization.

Functions

Link copied to clipboard
open override fun decrypt(value: String): String

Decrypts previously encrypted text back to its original form. Implementations should ensure:

Link copied to clipboard
open override fun encrypt(text: String): String

Encrypts the given text using the implementation-specific algorithm. Implementations should ensure: