Rust · From scratch · RFC 8439

Authenticated encryption
you can actually read.

Cipherlock is a single binary that implements a real modern AEAD, ChaCha20-Poly1305, from scratch. Encrypt and decrypt files with a passphrase, or read the source to see exactly how authenticated encryption works.

View on GitHub How it works

Try it in your browser

This is a second, independent implementation of the same ChaCha20-Poly1305 construction, written in plain JavaScript and running entirely on this page. Nothing you type here leaves your browser.

ENCRYPT

 
 
 
 

DECRYPT

 

encrypt then decrypt to recover the text · tamper flips one ciphertext bit

How it works

Two primitives, combined encrypt then authenticate, so a wrong passphrase or a tampered file fails loudly.

1

ChaCha20

A stream cipher that expands a 256 bit key, a 96 bit nonce, and a counter into a keystream using 20 rounds of add rotate xor quarter rounds. XORed with the plaintext, it produces the ciphertext.

2

Poly1305

A one time message authenticator. A fresh key is derived from ChaCha20 for every message, and the authenticator produces a 128 bit tag over the ciphertext and any associated data.

3

AEAD

The two are combined into AEAD_CHACHA20_POLY1305, encrypt then authenticate. Decryption verifies the tag before releasing any plaintext.

Run it from the command line

The same construction you just tried above, encrypting a real file on disk.

cargo build --release

cipherlock encrypt secret.txt secret.txt.lock --pass "correct horse battery staple"

cipherlock decrypt secret.txt.lock secret.txt --pass "correct horse battery staple"

Proof of correctness

Every primitive is checked against the official RFC 8439 known answer test vectors: the ChaCha20 block function vector, the ChaCha20 encryption vector, the Poly1305 vector, and the full AEAD vector. All four pass under cargo test, alongside an encrypt then decrypt roundtrip test and a tamper detection test that flips a ciphertext byte and confirms decryption fails. This is a correct, teaching grade tool. It is not a substitute for an audited cryptography library in production.