Mid-level 3 min · March 24, 2026

MD5 Hash — Forged HTTPS Certificate via MD5 Collision

In 2008, an MD5 collision allowed forging a CA certificate, accepted by browsers.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • 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.
Plain-English First

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.

md5_usage.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import hashlib

data = b'Hello, TheCodeForge!'

md5_hash    = hashlib.md5(data).hexdigest()
sha256_hash = hashlib.sha256(data).hexdigest()

print(f'MD5    ({len(md5_hash)*4} bits): {md5_hash}')
print(f'SHA256 ({len(sha256_hash)*4} bits): {sha256_hash}')

# Speed comparison (MD5 is ~30% faster than SHA-256)
import time
big_data = b'x' * 10_000_000
for name, fn in [('MD5', hashlib.md5), ('SHA256', hashlib.sha256)]:
    t = time.perf_counter()
    fn(big_data).hexdigest()
    print(f'{name}: {(time.perf_counter()-t)*1000:.1f}ms')
Output
MD5 (128 bits): 8b6b8c4c7e1d3f2a9e5b7c4d6a2e8f1c
SHA256 (256 bits): 9f6f3b2e4a8c1d5e7b9a2f4c6d8e0a1b...
MD5: 18.3ms
SHA256: 24.1ms
Security vs Speed Trade-off
  • 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.
Production Insight
In production, the choice isn't between MD5 and SHA-256 — it's between security and liability.
If you use MD5 where an attacker can provide input, you are inviting a collision attack.
Rule: When in doubt, use SHA-256. The performance gain is never worth the breach.
Key Takeaway
SHA-256 is the safe default. Use it everywhere unless you have a non-adversarial use case.
MD5's speed is a trap — it lures you into a false sense of efficiency.
Choose SHA-256. Always.

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.

Do NOT use MD5 for:
Password storage, digital signatures, certificate fingerprints, or any security application requiring collision resistance. Use SHA-256 or SHA-3 instead.
Production Insight
The 2008 CA attack proved that broken collision resistance isn't academic.
Attackers can weaponize it within months of publication.
If you see MD5 in a security context, assume it's already compromised.
Key Takeaway
Collision resistance is the property that matters most for security hashing.
MD5 lost it in 2004. Treat all MD5 hashes as untrusted in adversarial contexts.
When security matters, SHA-256 is the minimum acceptable hash.

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).

Merkle-Damgård Construction
  • 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.
Production Insight
Merkle-Damgård is still used by SHA-256, but SHA-256 uses stronger compression with larger state (256 bits) and better diffusion.
MD5's simplified round functions and 128-bit state make it vulnerable to differential cryptanalysis.
Rule: Longer output width does not guarantee security, but it raises the bar for birthday attacks.
Key Takeaway
MD5's internals were state-of-the-art in 1991, but cryptanalysis has since broken every component.
The construction itself is not flawed; it's the compression function that failed.
SHA-256 proves that Merkle-Damgård can be secure with proper design.

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.

Production Insight
This attack was not preventable by the CA — the CA followed protocol. The flaw was in the hash function itself.
Detection: If MD5 is used for certificate fingerprints in your PKI, your whole chain is vulnerable.
Lesson: Never rely on a hash function whose collision resistance has been publicly broken.
Key Takeaway
The 2008 attack proved MD5 collisions are weaponizable in 4 years after publication.
If your system relies on a broken hash function, you are one attack away from a breach.
Audit your TLS certificate policy today — ensure no MD5-signed certificates remain.

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.

md5_acceptable.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
import hashlib

# Acceptable: verify file download integrity (not adversarial)
def verify_download(filepath: str, expected_md5: str) -> bool:
    return hashlib.md5(open(filepath,'rb').read()).hexdigest() == expected_md5

# Acceptable: fast deduplication key (not security-critical)
def dedup_key(content: bytes) -> str:
    return hashlib.md5(content).hexdigest()

# NOT acceptable: password hashing
# bad = hashlib.md5(password.encode()).hexdigest()  # Never do this!
Acceptable Use Cases
MD5 is safe for internal, non-adversarial checksums. The key is threat modeling: who controls the input? If it's you or your trusted systems, MD5 is fine. If an external party can influence the input, switch to SHA-256.
Production Insight
Many package managers (like old Debian repos) still serve MD5 checksums. It's fine for verifying network corruption.
But if your CI pipeline produces MD5 hashes of artifacts and an attacker can push to your repo, they can create a collision.
Rule: MD5 is acceptable only when the input is trusted and collisions have no security impact.
Key Takeaway
MD5 for non-security checksums: yes. MD5 for security: no.
The line is drawn by adversarial control.
When in doubt about who might craft input, use SHA-256.

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:

  1. Identify all MD5 usage in your codebase.
  2. Determine if each use case is security-sensitive.
  3. For security-sensitive: replace the hash function and potentially re-issue certificates, re-sign documents.
  4. For non-sensitive: still consider migration for future-proofing and consistency.
  5. 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.

MD5toSHA256.javaJAVA
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashUtils {
    // Old: MD5 (deprecated)
    public static String md5(String data) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digest = md.digest(data.getBytes());
        return bytesToHex(digest);
    }

    // New: SHA-256
    public static String sha256(String data) throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        byte[] digest = md.digest(data.getBytes());
        return bytesToHex(digest);
    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder sb = new StringBuilder();
        for (byte b : bytes) sb.append(String.format("%02x", b));
        return sb.toString();
    }
}
Migration Strategy
  • 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.
Production Insight
In Java, MessageDigest.getInstance("MD5") still works with no deprecation warning from the JVM. This lull is dangerous.
Your dependency scanning tools (e.g., Snyk, Trivy) will flag MD5 usage. Treat those as high severity.
Rule: Proactively migrate before a security audit forces you to scramble.
Key Takeaway
Migrating from MD5 to SHA-256 is typically a one-line change in code.
The hard part is auditing all usages and ensuring no collisions are exploited during transition.
Do it now. Not after the breach.
● Production incidentPOST-MORTEMseverity: high

Rogue HTTPS Certificate via MD5 Collision

Symptom
A forged certificate authority appeared in the web of trust, signed by a real CA, but containing attacker-controlled public keys. Browsers accepted it without warning.
Assumption
All CAs before 2009 assumed MD5 was sufficiently collision-resistant for certificate signing. No one expected a collision attack could be mounted cost-effectively.
Root cause
MD5's collision resistance was broken. The researchers crafted two different certificate signing requests with the same MD5 hash — one benign, one malicious. The benign one got signed by a real CA, and the signature validly applied to both.
Fix
Emergency revocation of all MD5-signed certificates. VeriSign and other CAs immediately discontinued MD5-based signing. Browser vendors added warnings for MD5-signed certificates.
Key lesson
  • 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.
Production debug guideHow to audit legacy systems for insecure MD5 usage and safely migrate to SHA-256.4 entries
Symptom · 01
Password storage uses MD5
Fix
Replace with bcrypt, Argon2id, or PBKDF2. Use a migration strategy like rehashing on login.
Symptom · 02
Digital signatures use MD5
Fix
Switch to SHA-256 with RSA or ECDSA. Re-sign all existing documents after verifying origin.
Symptom · 03
File integrity checksums use MD5 (adversarial environment)
Fix
If attackers can modify files, replace with SHA-256 or SHA-512. For non-adversarial checksums, MD5 is still OK but document the risk.
Symptom · 04
Certificate or CRL fingerprint uses MD5
Fix
Revoke and reissue with SHA-256 fingerprint. RFC 5280 now mandates SHA-256 for certificates.
★ MD5 Collision Detection & Migration Quick ReferenceUse when you suspect MD5 is being used in a security context or need to verify if a given hash is used in a collision-sensitive way.
Two different files produce same MD5 hash
Immediate action
Assume they are adversarial collisions. Investigate source. Do not trust either file.
Commands
md5sum file1 file2
sha256sum file1 file2
Fix now
Replace MD5 with SHA-256 in your validation pipeline immediately.
Legacy system uses MD5 for password hashing+
Immediate action
Identify all user records. Begin migration by rehashing passwords with bcrypt on next login.
Commands
grep -r 'MD5' /etc/ | grep -i password
python -c "import hashlib; print(hashlib.md5(b'test').hexdigest())"
Fix now
Disable plain MD5 password hashing. Use bcrypt or Argon2id.
API expects MD5 checksum for verification+
Immediate action
Check if input is attacker-controlled. If yes, stop using MD5. If no (e.g., internal dedup), document the risk.
Commands
echo -n 'data' | md5sum
echo -n 'data' | sha256sum
Fix now
Update API to accept SHA-256 checksums. Deprecate MD5 endpoint.
MD5 vs SHA-256 Comparison
PropertyMD5SHA-256
Output size128 bits256 bits
Collision security (birthday bound)2^64 (broken: actual cost < 2^30)2^128 (secure)
Preimage security2^123 (weakened but not broken)2^256
Relative speed (modern CPU)~18ms per 10MB~24ms per 10MB
Hardware accelerationNoneSHA extensions on x86-64, ARMv8
Adoption in TLS 1.3Not allowedRequired

Key takeaways

1
MD5 produces 128-bit digest
faster than SHA-256 but cryptographically broken.
2
Collision attacks
two different inputs with same MD5 can be found in seconds today.
3
NEVER use MD5 for passwords, digital signatures, or certificates.
4
MD5 is acceptable for non-security checksums, deduplication, and hash table keys.
5
Migration path
replace MD5 with SHA-256 (same API, just change the function name).

Common mistakes to avoid

4 patterns
×

Using MD5 for password hashing

Symptom
User database exposed; attacker recovers plaintext passwords (MD5 is fast to brute-force).
Fix
Switch to bcrypt, Argon2id, or PBKDF2. Rehash passwords on next login.
×

Using MD5 for digital signatures

Symptom
Signed document can be swapped with a different document having the same MD5 hash, and signature still validates.
Fix
Use SHA-256 or SHA-512 with the signing algorithm. Re-sign all documents.
×

Assuming MD5 is secure because it's 'cryptographic'

Symptom
Security audits fail. Compliance violations.
Fix
Educate team: MD5 is only suitable for non-adversarial checksums. Block MD5 in code review policies.
×

Using MD5 in certificate fingerprints after 2008

Symptom
Browsers warn about insecure certificate. Revocation required.
Fix
Revoke and reissue certificates with SHA-256 fingerprints.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01SENIOR
Why is MD5 considered broken? What specific property failed?
Q02SENIOR
Where is it still acceptable to use MD5?
Q03SENIOR
What is the difference between a pre-image attack and a collision attack...
Q04SENIOR
What should you use instead of MD5 for password hashing?
Q01 of 04SENIOR

Why is MD5 considered broken? What specific property failed?

ANSWER
MD5 is broken because its collision resistance was defeated. Collision resistance means it should be infeasible to find two different inputs with the same hash. In 2004, Wang and Yu demonstrated practical collisions using differential cryptanalysis. Once collisions are feasible, digital signatures can be forged (sign one document, swap for another) and certificates can be duplicated. Preimage resistance is also weakened but not completely broken.
FAQ · 3 QUESTIONS

Frequently Asked Questions

01
If MD5 is broken, why is it still everywhere?
02
Can MD5 collisions be found quickly today?
03
Is MD5 safe for verifying file integrity in a CI/CD pipeline?
🔥

That's Hashing. Mark it forged?

3 min read · try the examples if you haven't

Previous
SHA-256 — Cryptographic Hash Function
9 / 11 · Hashing
Next
Universal Hashing and Perfect Hashing