Small AES-GCM primitive module used by KMS and available for crypto-only mode.
This module intentionally exposes only a narrow set of operations:
- generate base64-encoded AES keys;
- derive base64-encoded AES keys from input/salt using HMAC-SHA256;
- encrypt/decrypt binaries with AES-GCM and optional AAD.
Keys are base64-encoded strings containing 16, 24, or 32 raw bytes. Ciphertexts
are base64-encoded iv <> tag <> ciphertext payloads.
Use higher-level KMS.encrypt_alias/3 when you want KMS-managed KEKs. Use this
module directly only when the application owns key storage and decrypt policy.
Summary
Functions
Decrypts ciphertext created by encrypt/3.
Returns plaintext binary on success. Returns :error when authentication fails.
Raises if the key or ciphertext encoding is malformed.
Derives a base64-encoded AES key from input and salt.
Options:
:length- output byte length, defaults to16.:info- context string, defaults to"kms-derived-key".
Use distinct :info values for distinct key purposes.
Encrypts plaintext with AES-GCM.
data_key must be a base64-encoded key from generate_key/1 or derive_key/3.
aad is additional authenticated data. It is not secret, but the same value is
required by decrypt/3.
Generates a base64-encoded AES key.
key_size is raw byte length and must be 16, 24, or 32.
Defaults to 16 bytes (AES-128). Use 32 for AES-256.