MD5 Hash — Forged HTTPS Certificate via MD5 Collision
In 2008, an MD5 collision allowed forging a CA certificate, accepted by browsers.
- MD5 is a 128-bit cryptographic hash function using the Merkle-Damgård construction.
- Key components: compression function, message padding, initialization vectors.
- Collision resistance is broken: collisions found in seconds on consumer hardware.
- Performance: ~30% faster than SHA-256, but the speed comes at the cost of security.
- Production insight: Do not use MD5 for security-critical applications — attacker can forge digital signatures and certificates.
- Biggest mistake: Treating MD5 as secure for any purpose involving adversarial input.
MD5 produces a 128-bit fingerprint of any data. For years it was trusted for security — but in 2004, researchers found two different inputs that produce the same MD5 hash. Once collisions can be found, the security foundation collapses. MD5 is now broken for security purposes, but still widely used where collision resistance isn't needed — like checking file integrity.
In 2008, a team of researchers created a rogue HTTPS certificate authority using MD5 collisions. They found two different certificate requests that produced the same MD5 hash, had one signed by a real CA, and used the signature to forge a certificate that browsers trusted completely. Every HTTPS connection in every browser would have accepted the forged certificate as legitimate. This was not a theoretical attack — it was demonstrated at CCC 2008 and forced emergency certificate revocation across the internet.
MD5 was deprecated for security use in 2004 when Wang and Yu demonstrated practical collisions. Yet in 2026, it remains widely used for non-security checksums. Understanding why MD5 is broken for security but fine for checksums requires understanding which cryptographic property failed and why that property matters.
MD5 vs SHA-256 — Quick Comparison
MD5 and SHA-256 both belong to the MD4 family of hash functions, but while MD5 was designed for 32-bit architectures and speed, SHA-256 was built with security margins from the start. The biggest practical difference is the output length: MD5 produces 128 bits, SHA-256 produces 256 bits. That alone makes SHA-256 2^128 times harder to brute-force for preimage attacks.
The speed advantage of MD5 (~30% faster) is not worth the security risk in any adversarial scenario. Modern CPUs and hardware acceleration (like SHA intrinsics) have narrowed the gap.
- Collision resistance: SHA-256 provides 2^128 security level (birthday bound); MD5 provides none since 2004.
- Preimage resistance: MD5 has effective security of ~2^123, but collisions are the real threat.
- Performance: MD5 is faster but not by enough to justify risk in most cases.
Why MD5 is Broken
MD5's fatal flaw: collision attacks. A collision is two different inputs with the same hash.
2004: Wang and Yu find MD5 collisions in hours on standard hardware. 2005: Collisions found in ~1 hour on a notebook. 2008: Researchers create rogue HTTPS certificates using MD5 collisions — real-world attack. Today: MD5 collisions can be found in seconds on consumer hardware.
This breaks: digital signatures (attacker can swap signed document), certificate validation, and any application requiring collision resistance.
How MD5 Works (Merkle-Damgård Construction)
MD5 processes messages in 512-bit blocks using the Merkle-Damgård construction. The message is padded to a multiple of 512 bits (with a 1, zeros, and 64-bit length appended). Then each block goes through a compression function that mixes four 32-bit registers (A, B, C, D) using non-linear functions (F, G, H, I) and constant tables.
The core loop runs 64 rounds per block, using left rotations and modular additions. The output is the final concatenation of A, B, C, D — 128 bits total.
Understanding this construction is key to seeing why collision resistance fails: the compression function has differential paths that can be exploited, and the 128-bit output provides only 64-bit collision security (birthday bound).
- Message is split into 512-bit blocks; last block includes padding and length.
- Each block updates an internal state (four 32-bit registers).
- Final state becomes the hash output (128 bits).
- Weakness: once a collision is found in one block, it propagates through all subsequent blocks.
The 2008 CA Forgery Attack — Real-World Collision Exploitation
At the 25th Chaos Communication Congress (CCC) in December 2008, researchers Alexander Sotirov, Marc Stevens, and others demonstrated what many had feared: they used MD5 collisions to create a rogue Certificate Authority that browsers would trust.
They crafted two different X.509 certificate signing requests that had the same MD5 hash. One was a legitimate request to a real CA (RapidSSL at the time). The CA signed it, creating a valid signature. Because both requests had the same hash, the signature was also valid for the second, malicious certificate — which contained a CA flag and a public key the attackers controlled.
The attack required a cluster of 200 PlayStation 3 consoles (about $10k in hardware) and a clever exploitation of the CA's random serial number generation. It forced immediate revocation of all MD5-signed certificates from major CAs.
Where MD5 is Still Acceptable
MD5 remains appropriate when collision resistance is not a security requirement:
File checksums (non-adversarial): Verifying a download wasn't corrupted in transit (not tampered with by an attacker). Hash tables / data deduplication: When adversarial collisions aren't a concern. Non-cryptographic fingerprinting: Database row hashing for quick equality checks. Legacy protocol compatibility: MD5 is still in some network protocols where migration is impractical.
Rule: if an attacker controls the input, never use MD5.
Migrating from MD5 to SHA-256
Replacing MD5 with SHA-256 is straightforward in most codebases. The API is identical in most languages (Python's hashlib, Java's MessageDigest, OpenSSL). The migration involves:
- Identify all MD5 usage in your codebase.
- Determine if each use case is security-sensitive.
- For security-sensitive: replace the hash function and potentially re-issue certificates, re-sign documents.
- For non-sensitive: still consider migration for future-proofing and consistency.
- Update documentation to explicitly forbid MD5 in security contexts.
If you need backward compatibility with systems that only accept MD5, consider offering both hashes during a transition period.
- Phase 1: Audit — grep your source for 'MD5', 'MessageDigest.getInstance("MD5")', 'hashlib.md5'.
- Phase 2: Categorize — security vs non-security use cases.
- Phase 3: Replace — one function call change for most cases.
- Phase 4: Test — verify new hashes match expected values (if deterministic).
- Phase 5: Sunset — remove MD5 support after transition period.
Rogue HTTPS Certificate via MD5 Collision
- Never use a hash function with broken collision resistance for digital signatures or certificates.
- Collision attacks are not theoretical — they can be weaponized in months once discovered.
- Always prefer SHA-256 or SHA-3 for security-critical hashing.
Key takeaways
Common mistakes to avoid
4 patternsUsing MD5 for password hashing
Using MD5 for digital signatures
Assuming MD5 is secure because it's 'cryptographic'
Using MD5 in certificate fingerprints after 2008
Interview Questions on This Topic
Why is MD5 considered broken? What specific property failed?
Frequently Asked Questions
That's Hashing. Mark it forged?
3 min read · try the examples if you haven't