← Cryptography

🛡️ Encryption

Encrypt and decrypt with AES (GCM, CBC, CTR) and ChaCha20-Poly1305.

Notes

GCM and the ChaCha20 ciphers are authenticated: decryption fails if the ciphertext, tag, IV or associated data were changed. CBC and CTR are not; anyone can flip bits without detection, so pair them with a MAC. Never reuse an IV/nonce with the same key — with GCM, CTR and ChaCha20 that leaks the XOR of the plaintexts. XChaCha20’s 24-byte nonce is large enough to pick at random safely. The authentication tag (16 bytes) is appended to the ciphertext, which is the usual layout (WebCrypto, libsodium, Go).