๐Ÿ”’
๐Ÿ”’ Security & Identity with the Larz Stack ยท SEC-101 ยท Session 2 of 5

Hashing & Encryption with larzcrypt

The two workhorses of security: hashing (for passwords and integrity) and encryption (for confidentiality). larzcrypt provides both correctly, verified against the official standards.

โฑ 8 min read๐Ÿ“… Updated 2026-07-27๐Ÿ“Š Tables, charts & examples

Two cryptographic operations underpin most security: hashing (a one-way fingerprint, used for passwords and integrity) and encryption (reversible scrambling for confidentiality). Using them correctly is essential and easy to get subtly wrong. larzcrypt provides both via standard algorithms verified against RFC test vectors, so you use them right without implementing them.

Hashing: passwords and integrity

A hash is a one-way fingerprint - you can't reverse it. That's exactly why it's used to store passwords (store the hash, never the password) and to verify data hasn't changed.

from larzcrypt import hash_password, verify_password

stored = hash_password('correct horse battery staple')  # scrypt, salted
# store `stored` in your DB - never the raw password
verify_password('correct horse battery staple', stored)   # True
UseHow
Store passwordshash_password (scrypt, salted) - never plaintext
Check a passwordverify_password against the stored hash
Verify integrity/authenticityHMAC - detect tampering
Fingerprint dataSHA-2/3, BLAKE2

The golden rule: never store a password itself, only a strong, salted hash of it - so even a database breach doesn't hand attackers the passwords.

Encryption: confidentiality, authenticated

Encryption keeps data secret. Modern practice uses 'authenticated' encryption, which also detects tampering - larzcrypt provides ChaCha20-Poly1305 for this.

๐ŸŽฏ
Use authenticated encryption (AEAD). Plain encryption hides data but can't tell you if it's been tampered with; authenticated encryption (AEAD, like ChaCha20-Poly1305) both hides the data and guarantees it wasn't altered - which is what you almost always want. larzcrypt provides it, along with key exchange (X25519), signatures (Ed25519), key-derivation (PBKDF2/scrypt/HKDF) and an alg-confusion-proof JWT - all standard algorithms, all verified against their RFC test vectors, and honest that they aren't side-channel-hardened like libsodium.

Use crypto correctly

  • Hash passwords - scrypt, salted; never store plaintext.
  • HMAC for integrity/authenticity.
  • Authenticated encryption (AEAD) for confidentiality + tamper-detection.
  • Standard, verified - larzcrypt matches RFC 8439/7748/8032/5869/4231 vectors.

๐ŸŽฏ Key takeaways

  • Hashing is a one-way fingerprint (for passwords and integrity); encryption is reversible (for confidentiality).
  • Never store passwords - store a strong salted hash (scrypt); verify against it.
  • Use authenticated encryption (AEAD, ChaCha20-Poly1305) so data is both secret and tamper-evident.
  • larzcrypt provides these via standard algorithms verified against official RFC test vectors.

Frequently asked

Why can't I just store passwords encrypted instead of hashed?

Because encryption is reversible - if you encrypt passwords, then whoever has the decryption key (you, or an attacker who steals it) can recover every password in plaintext, which is exactly the disaster you're trying to prevent. Hashing is one-way: you store a fingerprint that can verify a password (by hashing the attempt and comparing) but can't be reversed back into the password, so even a full database breach doesn't directly expose passwords. That's why the correct approach is a strong, salted password hash (like scrypt), never encryption and never plaintext. The salt ensures identical passwords don't produce identical hashes, defeating precomputed-table attacks.

What's 'authenticated encryption' and why does it matter?

Plain encryption only guarantees confidentiality - it hides the data - but it doesn't tell you whether the ciphertext was tampered with in transit or storage, and naive encryption can be manipulated in ways that cause subtle, serious vulnerabilities. Authenticated encryption (AEAD), like ChaCha20-Poly1305, adds an integrity/authenticity guarantee: on decryption it verifies the data wasn't altered and rejects it if it was. This is almost always what you actually want, because you care both that data is secret and that it's genuine. Using AEAD by default (as larzcrypt encourages) avoids a whole class of mistakes that come from using encryption without integrity protection.

Session 2 of 5 complete

Next up: Managing Secrets with larzvault

Continue to Session 3 โ†’

Related lessons

More in this course

Course home → · Browse all courses →