Last updated
Quick Reference: When to Use Which Hash
- File integrity verification: SHA-256 or SHA-512
- Digital signatures: SHA-256 (RSA/ECDSA) or SHA-3
- Password storage: Argon2id (preferred), bcrypt, or scrypt
- Message authentication (HMAC): HMAC-SHA-256
- Non-security checksums: MD5 or CRC32 (fast, not secure)
- High-performance hashing: BLAKE3
- Never use MD5 or SHA-1 for any security purpose
Examples
Example 1: What Is a Hash Collision?
A hash collision occurs when two different inputs produce the same hash output.
Example (MD5 collision — real, demonstrated by researchers):
Input A: d131dd02c5e6eec4693d9a0698aff95c...
Input B: d131dd02c5e6eec4693d9a0698aff95c... (different bytes)
MD5(Input A) = 79054025255fb1a26e4bc422aef54eb4
MD5(Input B) = 79054025255fb1a26e4bc422aef54eb4
← Same hash, different inputs = COLLISION
Why this matters:
If you use MD5 to verify file integrity, an attacker can create
a malicious file with the same MD5 hash as a legitimate file.
Example 2: Birthday Paradox and Hash Collisions
The birthday paradox: In a group of 23 people, there is a ~50% chance
two share a birthday (out of 365 possible birthdays).
Applied to hash functions:
Hash output size | Bits | Collision likely after
-----------------|------|------------------------
MD5 | 128 | ~2^64 = 18 quintillion operations
SHA-1 | 160 | ~2^80 = 1.2 × 10^24 operations
SHA-256 | 256 | ~2^128 = 3.4 × 10^38 operations
SHA-512 | 512 | ~2^256 = astronomically large
MD5 collisions are now practical with modern hardware.
SHA-1 collisions were demonstrated by Google's SHAttered attack (2017).
SHA-256 collisions remain computationally infeasible.
Example 3: MD5 — Broken for Security
MD5 is still widely used for checksums but MUST NOT be used for security:
# MD5 of two different files can be identical (collision attack)
echo "Hello World" | md5sum
→ e59ff97941044f85df5297e1c302d260
# MD5 collision example (simplified):
File 1: legitimate_installer.exe → MD5: abc123...
File 2: malicious_installer.exe → MD5: abc123... ← SAME HASH!
# An attacker can distribute malicious_installer.exe
# and it will pass MD5 integrity checks.
Safe uses of MD5:
✅ Non-security checksums (detecting accidental corruption)
✅ Cache keys (where collision resistance is not required)
❌ Digital signatures
❌ Password hashing
❌ Certificate fingerprints
❌ File integrity verification for security purposes