Hashing vs Encryption vs Encoding
Encoding is reversible without a secret, hashing is one-way, encryption is reversible with a key — three different tools that are routinely confused, and the confusion produces real vulnerabilities.
Frame the problem
Security starts with a concrete asset, attacker capability and trust crossing.
Three operations
Base64 in a token is not protection; a URL decoder in a browser tab reverses it. A hash of a phone number is reversible by hashing every phone number — hashing only hides *high-entropy* input. Encryption with the key in the same config file as the ciphertext protects against nothing that has the config file.
| Encoding | Hashing | Encryption | |
|---|---|---|---|
| Purpose | Represent data in another form | Fingerprint data; one-way | Hide data from those without the key |
| Reversible? | Yes, by anyone | No | Yes, with the key |
| Needs a secret? | No | No (a salt is not a secret) | Yes — the key |
| Examples | Base64, URL-encoding, hex | SHA-256, Argon2 (password) | AES-GCM, ChaCha20-Poly1305 |
| Provides | Nothing security-wise | Integrity check; password verification | Confidentiality (+ integrity if authenticated) |
| Common misuse | "Encrypted" tokens that are base64 | Fast hashes for passwords; hashing low-entropy data | Key stored next to the data; unauthenticated modes |
Choosing
Need to transport bytes safely in text? Encode. Need to verify a password or detect modification of something you also hold? Hash (slow hash for passwords, keyed MAC if the attacker could rewrite the hash too). Need to read the data back later and keep others out? Encrypt, authenticated, with the key in a separate system.
Key points
- Encoding provides no security.
- Hashing hides only high-entropy input; hashing an email is not anonymisation.
- Encryption protects only against parties without the key — so where the key lives is the whole question.
- "Encrypt the password" is a red flag; passwords are hashed.
Boundary control exercise
This lesson uses the shared boundary-control exercise.
Follow the attack
Safe conceptual simulation: capability → missing control → crossed boundary → asset impact.
- 1Attacker → decode the "encrypted" token; or enumerate the domain of a hashed low-entropy value; or find the key beside the data.
- Protection that was believed to exist did not; data is effectively plaintext.
Defend, detect, recover
One prevention is a single point of security failure. Layer it and make failure observable.
- • Name the property needed; pick the operation that provides it.
- • Keys in a key-management system, not config.
- • Slow hashes for passwords; MAC when an attacker could rewrite the hash.
- • Review for base64 called "encryption"; hashes of identifiers used as anonymisation.
- • Treat the data as exposed; re-protect properly.
- • Correct primitives still fail with wrong key handling.