Skip to main content
AesGcm provides NIST SP 800-38D authenticated encryption (AES-128-GCM and AES-256-GCM) over the native WebCrypto API (crypto.subtle). All encryption, decryption, and key-management functions are asynchronous and operate on WebCrypto CryptoKey objects.

Encryption Pipeline

Quick Start

Password-Derived Keys (PBKDF2-SHA256)

API Reference

All functions are exported on AesGcm and as named exports from @tevm/voltaire/AesGcm.

Constants

Errors and Security Invariants

Never reuse a (key, nonce) pair. A single repeated nonce in AES-GCM leaks the XOR of both plaintexts and exposes the GHASH authentication key, allowing arbitrary ciphertext forgery.
  • Error types: Wrong nonce length throws InvalidNonceError; wrong raw key length throws InvalidKeyError; tampered ciphertext, wrong key, wrong nonce, or mismatched AAD throws DecryptionError; other WebCrypto failures throw AesGcmError.
  • Nonce storage: Store the 12-byte nonce with the ciphertext (for example, nonce || ciphertext). Nonces are not secret.
  • PBKDF2 iterations: Use at least 600_000 iterations with PBKDF2-SHA256 and a random 16-byte salt for user passwords.