Crypto You Actually Need as a Developer
Hashing vs encryption, how to store passwords without regret, what TLS gives you, and the one rule that keeps you out of trouble — don't roll your own.
You don't need to be a cryptographer, but a few clear distinctions prevent the mistakes that cause real breaches.
Hashing is not encryption
They're often confused; they solve different problems.
| Encryption | Hashing | |
|---|---|---|
| Reversible? | Yes, with the key | No, one-way |
| Purpose | confidentiality | integrity / verification |
| Example | TLS protecting traffic | verifying a download, storing passwords |
Encryption scrambles data so it can be recovered with a key. Hashing maps data to a fixed-size fingerprint that can't be reversed — you can only check whether something produces the same hash.
Storing passwords
Never store passwords, and never "encrypt" them (encryption is reversible — a leaked key exposes them all). Instead, store a slow, salted password hash:
# use a purpose-built password hash
from argon2 import PasswordHasher
ph = PasswordHasher()
stored = ph.hash(password) # includes a random salt automatically
ph.verify(stored, attempt) # checks a loginThree properties matter:
- Salt — a random value per password, so identical passwords hash differently and precomputed ("rainbow") tables are useless. Modern hashers add it for you.
- Slow — Argon2, bcrypt or scrypt are deliberately expensive, so brute-forcing a leak is painful. Never use fast hashes (MD5, SHA-256) for passwords.
- Verify, don't decrypt — you compare hashes; you never recover the original.
What TLS actually gives you
TLS (the S in HTTPS) provides three things at once: confidentiality (eavesdroppers can't read it), integrity (tampering is detected), and authentication (the certificate proves you're talking to the real server). Inspect a server's certificate chain:
openssl s_client -connect example.com:443 -servername example.com </dev/nullSymmetric vs asymmetric, briefly
- Symmetric (AES): one shared key encrypts and decrypts. Fast; the challenge is sharing the key.
- Asymmetric (RSA, elliptic curve): a public key encrypts / verifies, a private key decrypts / signs. Solves key exchange, but slow.
Real systems combine them: asymmetric crypto to agree on a key, then fast symmetric crypto for the bulk data. That's exactly what TLS does.
Takeaways
- Encryption is reversible (confidentiality); hashing is one-way (integrity/verification) — don't mix them up.
- Store passwords as slow, salted hashes (Argon2/bcrypt/scrypt), never encrypted, never with fast hashes.
- TLS delivers confidentiality, integrity and authentication together.
- Combine asymmetric (key exchange) with symmetric (bulk) — and never roll your own crypto; use vetted libraries.