Skip to content
Already broken todaymd5

MD5

A 128-bit hash from 1992 that is still common in legacy code, checksums and old password databases.

Why it's at risk

MD5 collisions can be produced in seconds on a laptop and were used in real attacks such as forged certificates and the Flame malware. It must not be used for signatures, certificates, integrity against attackers or password storage. For non-security checksums it still works, but SHA-256 costs little more.

Used for
Hash
Family
Hash function (Merkle-Damgard)
Standards
RFC 1321, RFC 6151
Read the guideWhat encryption actually does

Migration guides

Concrete code changes to move off MD5. Pick your stack.

node:crypto · javascriptNode.js: replace MD5 and SHA-1 (hashes, HMACs and password hashing)Production-ready

Why

MD5 and SHA-1 are broken by ordinary computers: collisions are cheap (seconds for MD5; demonstrated in practice for SHA-1, including chosen-prefix collisions). They must not be used for signatures, certificates, integrity against attackers, or passwords. This is not a quantum problem, it is a today problem, and fixing it is usually quick.

Choose the replacement by purpose:

PurposeUse
Integrity / fingerprints / content addressingSHA-256 (or SHA-384/512, SHA3-256)
Message authentication with a keyHMAC-SHA-256
Password storageArgon2id (or scrypt; bcrypt is acceptable) — never a plain hash
Non-security checksums (cache keys, dedup with no attacker)MD5 is tolerable, but SHA-256 avoids scanner noise and future misuse

Before

js
import { createHash, createHmac } from 'node:crypto';

const etag = createHash('md5').update(body).digest('hex');
const sig = createHmac('sha1', secret).update(payload).digest('hex');
const pwHash = createHash('sha1').update(password + salt).digest('hex'); // never do this

After

js
import { createHash, createHmac, timingSafeEqual, scrypt, randomBytes } from 'node:crypto';
import { promisify } from 'node:util';

const etag = createHash('sha256').update(body).digest('hex');

const sig = createHmac('sha256', secret).update(payload).digest();
const expected = Buffer.from(receivedSignatureHex, 'hex');
const ok = expected.length === sig.length && timingSafeEqual(expected, sig); // constant-time compare

// Passwords: Argon2id via a maintained package (e.g. `argon2`), or scrypt built into Node:
const salt = randomBytes(16);
const hash = await promisify(scrypt)(password, salt, 32, { N: 2 ** 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 });
// store: algorithm id + params + salt + hash, e.g. "scrypt$17$8$1$<salt b64>$<hash b64>"

Gotchas

  • Stored data: existing MD5/SHA-1 digests (file manifests, dedup tables) need a migration plan: dual-write both hashes, backfill, then switch reads.
  • Password migration: you cannot re-hash without the password. Re-hash on next successful login, or wrap the old hash (argon2id(sha1(password))) immediately and mark the record.
  • Interop: external APIs that require HMAC-SHA1 (some webhooks, OAuth 1.0a, TOTP authenticator apps) may force you to keep it at that boundary; HMAC-SHA1 is not broken in the way plain SHA-1 is.
  • Git still uses SHA-1 object IDs by default (with collision detection); that is outside your code.
  • scrypt memory: N=2^17, r=8 needs about 128 MiB, so raise maxmem (default 32 MiB) as shown, and size your servers accordingly.

Verify

npx -y pqe-cli scan . should no longer report md5/sha1 findings outside allow-listed boundaries; add a unit test that the HMAC output length is 32 bytes.

hashlib / hmac / argon2-cffi · pythonPython: replace MD5 and SHA-1, and store passwords with Argon2idProduction-ready

Why

MD5 and SHA-1 collisions are practical with ordinary computers, so they are unsafe for signatures, integrity against attackers and password storage. Pick the replacement by purpose: SHA-256 for integrity, HMAC-SHA-256 for keyed authentication, Argon2id for passwords.

Before

python
import hashlib, hmac

digest = hashlib.md5(data).hexdigest()
tag = hmac.new(secret, payload, hashlib.sha1).hexdigest()
pw = hashlib.sha1((password + salt).encode()).hexdigest()   # never do this

After

python
import hashlib, hmac

digest = hashlib.sha256(data).hexdigest()

tag = hmac.new(secret, payload, hashlib.sha256).digest()
ok = hmac.compare_digest(tag, received_tag)                 # constant time

# Passwords: pip install argon2-cffi
from argon2 import PasswordHasher
ph = PasswordHasher()                                       # Argon2id with RFC 9106 low-memory defaults
stored = ph.hash(password)                                  # encodes params + salt + hash
ph.verify(stored, password)                                 # raises on mismatch
if ph.check_needs_rehash(stored):
    stored = ph.hash(password)

If you need MD5 for a non-security purpose (e.g. a legacy cache key), say so explicitly: hashlib.md5(data, usedforsecurity=False) (Python 3.9+). It also keeps FIPS-mode systems from rejecting the call.

Gotchas

  • PBKDF2 (hashlib.pbkdf2_hmac) is acceptable when FIPS is required; use SHA-256 with at least 600,000 iterations (OWASP guidance) and a 16-byte random salt.
  • Migrating passwords: re-hash on next login, or wrap old hashes (argon2id(old_sha1_hex)) right away and flag the records.
  • Django/Flask-Security etc. have their own hasher settings (PASSWORD_HASHERS); put Argon2 first rather than calling hashlib yourself.
  • External protocols that mandate HMAC-SHA1 (TOTP apps, some webhooks) can stay at that boundary.

Verify

npx -y pqe-cli scan . should show no remaining md5/sha1 findings outside intentional, documented spots.

JCA (javax.crypto / java.security) · javaJava: fix Cipher.getInstance("AES") (it means ECB), DES/3DES, MD5 and SHA-1Production-ready

Why

The most common Java crypto bug is Cipher.getInstance("AES"): with the default SunJCE provider that means AES/ECB/PKCS5Padding, which leaks patterns and has no integrity. DES/3DES/RC4/Blowfish and MD5/SHA-1 are weak against ordinary computers. Fixing these is quick and independent of the post-quantum work.

Before

java
Cipher c = Cipher.getInstance("AES");                  // = AES/ECB/PKCS5Padding
Cipher d = Cipher.getInstance("DESede/CBC/PKCS5Padding");
MessageDigest md = MessageDigest.getInstance("MD5");

After

java
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import java.security.*;

KeyGenerator kg = KeyGenerator.getInstance("AES");
kg.init(256);
SecretKey key = kg.generateKey();

byte[] iv = new byte[12];
SecureRandom.getInstanceStrong().nextBytes(iv);        // or new SecureRandom()
Cipher c = Cipher.getInstance("AES/GCM/NoPadding");
c.init(Cipher.ENCRYPT_MODE, key, new GCMParameterSpec(128, iv));
c.updateAAD(aad);
byte[] ct = c.doFinal(plaintext);                      // ciphertext || 16-byte tag
// store iv + ct (+ a format version byte)

MessageDigest sha = MessageDigest.getInstance("SHA-256");
Mac mac = Mac.getInstance("HmacSHA256");

Gotchas

  • Always spell out the full transformation (algorithm/mode/padding); provider defaults differ.
  • GCM IVs must be unique per key; the JDK refuses to reuse the same key+IV pair on one encrypting Cipher instance, but cannot protect you across instances.
  • getInstanceStrong() may block on some Linux configurations; new SecureRandom() is fine for IVs and keys.
  • Passwords: use a dedicated password hashing library (Argon2id, e.g. via Bouncy Castle or Spring Security's Argon2PasswordEncoder), not MessageDigest.
  • Legacy data: keep a decrypt-only path for old formats, then re-encrypt.

Verify

Round-trip test plus tamper test (AEADBadTagException expected), then npx -y pqe-cli scan ..