OxL Reference

data aead

Authenticated encryption with a 32-byte key. seal returns nonce(12) || ciphertext || tag(16) with a fresh random nonce; unseal verifies and decrypts. The associated data is authenticated but not encrypted and must be the same for both calls. Random 96-bit nonces are safe for about 2^32 messages per key.

Example:

oxl✓ checked in CI
use std.crypto { aead }
use std.ser { bytesOf, textOf }

fn main() io, rand {
  let key = bytesOf(&"0123456789abcdef0123456789abcdef")
  let sealed = aead.seal(key, bytesOf(&"top secret"), bytesOf(&"user-7"))!
  print(textOf(&aead.unseal(key, sealed, bytesOf(&"user-7"))!)!)
}
Output
top secret
pub(api) data aead

Thread safety. pure functions apart from the random nonce; safe from any task.

Since. 1.0.0-beta

Methods

seal(key: bytes, plain: bytes, aad: bytes) -> bytes | CryptoError rand
AES-256-GCM.
unseal(key: bytes, sealed: bytes, aad: bytes) -> bytes | CryptoError
Verifies and decrypts; a wrong key or modified data is a CryptoError.
sealChaCha(key: bytes, plain: bytes, aad: bytes) -> bytes | CryptoError rand
ChaCha20-Poly1305.
unsealChaCha(key: bytes, sealed: bytes, aad: bytes) -> bytes | CryptoError
Verifies and decrypts what sealChaCha produced; a wrong key or modified data is a CryptoError.

Defined in: std/crypto/crypto.oxl:433

See also