"Which hash should I use?" gets asked weekly, and the wrong answers are still shipping. A quick field guide.
1. MD5 and SHA-1 are fine for checksums, not for security
Both have practical collision attacks. Use them to detect accidental corruption or as cache keys, never for signatures or integrity against an attacker. Reach for SHA-256 or SHA-3 instead.
2. Never store passwords with a fast hash
SHA-256 is fast by design, which is exactly what an attacker with a GPU wants. Passwords need a slow, salted, memory-hard function: Argon2id, scrypt or bcrypt.
3. A hash is not encryption
You cannot "decrypt" a hash, but short or common inputs are trivially reversed by lookup tables. Add a salt, and use a keyed hash (HMAC) when you need authenticity.
4. Compare digests in constant time
Comparing with === can leak timing. Use crypto.timingSafeEqual in Node or the equivalent in your language when verifying HMACs or tokens.
5. Beware length-extension on naive "secret + message" hashes
SHA256(secret || message) is vulnerable to length extension. Use HMAC instead.
6. Identify before you assume
Given a mystery hex string, length is a strong hint: 32 hex chars is likely MD5, 40 is SHA-1, 64 is SHA-256, 128 is SHA-512. If you are poking at an unknown digest, a Hash Identifier helps, and a Hash Generator lets you compute MD5, SHA-1, SHA-256 and more locally. Both run in your browser, so nothing you paste leaves your machine.
Disclosure: I built WebDevToolbox, a free collection of 500+ browser-based dev tools. Everything runs client-side.
Top comments (0)