AES-128
AES with a 128-bit key, the most widely used symmetric cipher in the world.
Why it's at risk
Grover's algorithm nominally halves the key strength to about 64 bits, but Grover's search must run as one very long serial computation and parallelises badly, so the practical attack cost is far higher than 2^64. NIST uses AES-128 key search as the definition of its post-quantum Security Category 1 and treats AES-128 as acceptable. Moving long-lived or highly sensitive data to AES-256 is a cheap extra safety margin, and CNSA 2.0 requires AES-256 for US national security systems.
- Used for
- Symmetric encryption
- Family
- Block cipher (AES)
- Classical security
- 128 bits
- Against a quantum computer
- ~64 bits
- Standards
- FIPS 197, NIST SP 800-38D (GCM), NIST IR 8547
Migration guides
Concrete code changes to move off AES-128. Pick your stack.
node:crypto · javascriptNode.js: replace DES/3DES/RC4/Blowfish/ECB (and AES-128 for long-lived data) with AES-256-GCMProduction-ready
Why
DES (56-bit key) can be brute-forced; Triple DES and Blowfish have 64-bit blocks that leak data after a few tens of gigabytes (Sweet32); RC4 output is biased; ECB mode reveals patterns and has no integrity. None of these is a quantum issue: they are weak today. The fix is an authenticated cipher: AES-256-GCM or ChaCha20-Poly1305. AES-128-GCM is still acceptable (NIST treats AES-128 as post-quantum Security Category 1), but AES-256 adds margin for data that must stay secret for decades and is required by CNSA 2.0.
Before
import { createCipheriv } from 'node:crypto';
const c1 = createCipheriv('des-ede3-cbc', key24, iv8); // 3DES
const c2 = createCipheriv('aes-128-ecb', key16, null); // ECB: patterns + no integrity
const c3 = createCipheriv('bf-cbc', key, iv8); // BlowfishAfter
import { createCipheriv, createDecipheriv, randomBytes } from 'node:crypto';
function encrypt(key32, plaintext, aad = Buffer.alloc(0)) {
const iv = randomBytes(12); // unique per encryption with the same key
const c = createCipheriv('aes-256-gcm', key32, iv);
c.setAAD(aad);
const ct = Buffer.concat([c.update(plaintext), c.final()]);
return Buffer.concat([Buffer.from([1]), iv, c.getAuthTag(), ct]); // version byte | iv | tag | ct
}
function decrypt(key32, blob, aad = Buffer.alloc(0)) {
if (blob[0] !== 1) throw new Error('unknown format version');
const iv = blob.subarray(1, 13), tag = blob.subarray(13, 29), ct = blob.subarray(29);
const d = createDecipheriv('aes-256-gcm', key32, iv);
d.setAAD(aad);
d.setAuthTag(tag);
return Buffer.concat([d.update(ct), d.final()]); // throws if tampered
}'chacha20-poly1305' (with authTagLength: 16) is a good alternative on CPUs without AES acceleration.
Gotchas
- Never reuse an IV/nonce with the same GCM key. Random 96-bit IVs are fine up to about 2^32 messages per key; rotate keys before that, or use a counter.
- Keys must be random 32-byte values, not passwords. Derive from passwords with scrypt/Argon2, and from shared secrets with HKDF.
- Existing data: keep a decrypt-only path for the old format (the version byte makes this easy), re-encrypt on read or in a batch job, then delete the old path.
- Tag check: always call
setAuthTagbeforefinal(); skipping it removes the integrity guarantee. - Legacy algorithms may be unavailable: OpenSSL 3 moves DES, Blowfish and RC4 to the "legacy" provider, so old code may already fail on new Node versions.
Verify
Round-trip test, a tamper test (flip one byte, expect an exception), then npx -y pqe-cli scan . to confirm no des, 3des, rc4, blowfish or aes-ecb findings remain.
cryptography (pyca) AEAD · pythonPython: replace DES/3DES/RC4/Blowfish/ECB with AES-256-GCM or ChaCha20-Poly1305Production-ready
Why
These ciphers and modes are weak against today's computers (small keys, 64-bit blocks, biased keystreams, or no integrity). Use an AEAD from pyca/cryptography, which handles the mode and authentication correctly.
Before
from Crypto.Cipher import DES3, AES # PyCryptodome
c1 = DES3.new(key24, DES3.MODE_CBC, iv8)
c2 = AES.new(key16, AES.MODE_ECB) # patterns leak, no integrityAfter
import os
from cryptography.hazmat.primitives.ciphers.aead import AESGCM, ChaCha20Poly1305
key = AESGCM.generate_key(bit_length=256) # store in a KMS / secret manager
aead = AESGCM(key) # or ChaCha20Poly1305(ChaCha20Poly1305.generate_key())
nonce = os.urandom(12) # never reuse with the same key
blob = b"\x01" + nonce + aead.encrypt(nonce, plaintext, aad) # version | nonce | ct+tag
def decrypt(blob: bytes, aad: bytes) -> bytes:
assert blob[0] == 1, "unknown format"
return aead.decrypt(blob[1:13], blob[13:], aad) # raises InvalidTag if tamperedGotchas
- Nonce reuse with AES-GCM is catastrophic; random 96-bit nonces are fine for up to roughly 2^32 messages per key.
AESGCMSIV(pyca 42+) tolerates accidental reuse better. - Do not hand-roll CBC + HMAC unless you must interoperate; if you must, encrypt-then-MAC with separate keys.
- Password-derived keys need scrypt/Argon2 (
cryptography.hazmat.primitives.kdf.scrypt.Scrypt), not a hash of the password. - Old data: keep a decrypt-only path for the legacy format, re-encrypt, then remove it.
- PyCryptodome offers
AES.MODE_GCMtoo if you can't switch libraries; the same nonce rules apply.
Verify
Round-trip and tamper tests, then npx -y pqe-cli scan ..