Atom

crypto.encrypt()

Encrypts and authenticates bytes using AES-256-GCM.

Signature

crypto.encrypt(key, data[, associated_data])

Parameters

32-byte key, plaintext and optional authenticated data (empty by default). All are text/packed byte values.

Returns

Dictionary with nonce (12 bytes), data (ciphertext) and tag (16 bytes).

Behavior

Generates a fresh random nonce each time. Associated data is authenticated and left outside ciphertext.

Errors

Wrong key size, invalid bytes or backend failure.

Example

Atom
use crypto
k = crypto.random(32)
sealed = crypto.encrypt(k, 'Atom', 'record-v1')
assert(count(sealed.tag) == 16)