Hashing and IDs Cheat Sheet: SHA-256, HMAC, Argon2id, UUID v7
Checked against Hashes and unique IDs RFC 9562 (UUIDs), OWASP Password Storage Cheat Sheet as of Nov 2026; examples run on Node 24.4.0 and Python 3.12.8 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for backend developers who need to pick a hash function, store passwords, or choose an ID format for database keys. The hash rows were run on Node 24.4.0 and Python 3.12.8, and the password settings come from the OWASP Password Storage Cheat Sheet as it read on 28 Nov 2026. UUID rules follow RFC 9562, which replaced RFC 4122 in May 2024.
When to use what
Start by asking what the hash is protecting against. For a file checksum or a cache key where nobody is attacking you, SHA-256 is the boring default and BLAKE2 is a faster option when both sides support it. MD5 and SHA-1 still work as fingerprints for deduplication, but never use them where someone could craft a collision on purpose, such as signatures or certificates. RFC 6151 says this for MD5 and NIST is retiring SHA-1 entirely by the end of 2030.
If you need to prove a message came from someone holding a shared key, a plain hash is the wrong tool. Use HMAC-SHA256, and compare signatures with a constant-time function. Webhook signatures from most providers work this way.
Passwords are a separate problem. A fast hash lets an attacker try billions of guesses per second, so you want a slow, salted, memory-hard function. OWASP's order is Argon2id first, scrypt if Argon2id is not available, bcrypt only for legacy systems, and PBKDF2 when you need FIPS-140 compliance. Our password hashing guide covers migration from older schemes.
For IDs, I use UUID v7 for new database primary keys. The leading timestamp keeps inserts close together in a B-tree index, while v4 scatters them. Use v4 when the ID must not reveal when the record was created. ULID and Nano ID are popular libraries but not IETF standards, so pick them only when you control every system that parses the ID. The UUID versions guide and hash functions guide go deeper.
Digests below are for the input hello and were checked in both Node and Python. MD5's status comes from RFC 6151 (https://www.rfc-editor.org/rfc/rfc6151.html).
crypto.createHash('sha256').update('hello').digest('hex')Node: SHA-256 hex digest, 2cf24dba5fb0a30e...938b9824 for hello
hashlib.sha256(b'hello').hexdigest()Python: the same SHA-256 digest from the standard library
crypto.createHash('sha3-256')Node: SHA-3 256, a different construction from SHA-2 with the same output size
hashlib.blake2b(data, digest_size=32)Python: BLAKE2b cut to a 32-byte digest, a fast choice for checksums
crypto.createHash('md5')MD5 still runs but is broken for collisions; keep it to non-security fingerprints
RFC 6151: not acceptable where collision resistance is required.
crypto.createHash('sha1')SHA-1 has practical collision attacks; NIST retires it by 31 Dec 2030
shasum -a 256 file.tar.gzShell: checksum a download and compare it with the published value
RFC 6151 says HMAC-MD5 has no known practical break but new designs should not use it; HMAC-SHA256 is the usual choice.
crypto.createHmac('sha256', secret).update(body).digest('hex')Node: sign a webhook body with a shared secret
hmac.new(secret, body, 'sha256').hexdigest()Python: compute the same HMAC-SHA256 to verify an incoming signature
crypto.timingSafeEqual(a, b)Node: compare two equal-length buffers without leaking timing
Throws if the lengths differ, so check length first.
hmac.compare_digest(a, b)Python: constant-time comparison for signatures and tokens
Node 24.4.0 has no Argon2 in node:crypto, so the Argon2id and bcrypt rows need a library and were not run here.
argon2id m=19456 (19 MiB), t=2, p=1OWASP's minimum Argon2id setting and its first choice for new systems
scrypt N=2^17, r=8, p=1OWASP setting when Argon2id is unavailable; uses 128 MiB per hash
crypto.scryptSync(pw, salt, 32, { N: 2 ** 17, r: 8, p: 1, maxmem: 256 * 1024 * 1024 })Node: scrypt at the OWASP cost; raise maxmem or Node throws a memory limit error
bcrypt cost >= 10Legacy option; OWASP asks for a work factor of at least 10 and as high as your servers allow
bcrypt input <= 72 bytesOWASP says to enforce a maximum of 72 bytes, or less depending on the bcrypt implementation
PBKDF2-HMAC-SHA256, 600,000 iterationsOWASP setting when FIPS-140 compliance forces PBKDF2
$argon2id$v=19$m=19456,t=2,p=1$...Encoded hash format that stores algorithm, cost and salt with the hash
The version is the first hex digit of the third group: xxxxxxxx-xxxx-7xxx-... is v7.
crypto.randomUUID()Node and browsers: random v4 UUID generated by the runtime
uuid.uuid4()Python: random v4 UUID from the standard library
UUID v748-bit Unix millisecond timestamp, then random bits; sorts by creation time
uuid.uuid5(uuid.NAMESPACE_DNS, 'example.com')Python: name-based v5 (SHA-1), always cfbff0d1-9375-5685-968c-48ce8b15ae17 for this input
UUID v3Name-based like v5 but with MD5; RFC 9562 prefers v5
UUID v1 / v6Gregorian timestamp versions; v6 reorders v1 for index locality, and the RFC says use v7 instead
UUID v8Vendor-specific layout; only the version and variant bits are fixed
00000000-0000-0000-0000-000000000000Nil UUID: all 128 bits zero, handy as a sentinel
FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFFMax UUID: all bits set, new in RFC 9562
Neither is an IETF standard. Nano ID's defaults come from its README at https://github.com/ai/nanoid (version 6.0.2 on npm). The ulid npm package is at 3.0.2.
ULID128-bit ID written as 26 Crockford base32 characters; sorts lexicographically by time
ULID layout48-bit millisecond timestamp followed by 80 random bits
monotonicFactory()ulid package: keeps IDs in order when several are made in the same millisecond
nanoid()21-character URL-safe ID from the alphabet A-Za-z0-9_-
customAlphabet(alphabet, size)Nano ID: build a generator with your own alphabet and length
Worked example: Generate a UUID v7 in Node and read its timestamp back
Node 24.4.0 has crypto.randomUUID() for v4 but no v7 helper, so here is the RFC 9562 layout written by hand: six bytes of Unix milliseconds, then the version and variant bits over random data.
import crypto from 'node:crypto';
function uuidv7() {
const b = crypto.randomBytes(16);
const ts = BigInt(Date.now());
for (let i = 0; i < 6; i++) b[i] = Number((ts >> BigInt(8 * (5 - i))) & 0xffn);
b[6] = (b[6] & 0x0f) | 0x70; // version 7
b[8] = (b[8] & 0x3f) | 0x80; // variant 10
const h = b.toString('hex');
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
}
const id = uuidv7();
console.log(id, parseInt(id.replace(/-/g, '').slice(0, 12), 16));
One run printed:
01a21fd1-b7a4-7bad-b93e-a95032135eca 1795830167460
The 7 at the start of the third group is the version. The first 12 hex digits decode to 1795830167460, which was Date.now() at that moment, so anyone holding the ID can see roughly when it was made. Two IDs created 5 ms apart compared in creation order as plain strings, which is the property that keeps B-tree inserts cheap. In production I would use a maintained library rather than this snippet, because the RFC also describes optional counters for IDs made within the same millisecond.
Common mistakes
Storing passwords as SHA-256 of the password, even with a salt.
Use Argon2id with at least OWASP's 19 MiB, t=2, p=1 setting, or bcrypt with cost 10 or more on legacy stacks. Fast hashes are what attackers want.
Comparing HMAC signatures with
===or==.Use
crypto.timingSafeEqualin Node orhmac.compare_digestin Python so the comparison time does not leak how many bytes matched.Using UUID v7 for public IDs where the creation time is sensitive.
v7 embeds a millisecond timestamp anyone can decode. Use v4 for tokens or IDs that should reveal nothing.
Pre-hashing a password with SHA-256 and passing the raw bytes to bcrypt to dodge the 72-byte limit.
OWASP warns that raw digest bytes can contain null bytes. Encode the digest, for example as base64, or cap the password length instead.
Calling MD5 safe because HMAC-MD5 is not broken.
RFC 6151 only says HMAC-MD5 is not urgently broken. For signatures, certificates or any new design, use SHA-256 or newer.
Related cheat sheets
Sources
- https://www.rfc-editor.org/rfc/rfc9562.html
- https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
- https://www.nist.gov/news-events/news/2022/12/nist-retires-sha-1-cryptographic-algorithm
- https://www.rfc-editor.org/rfc/rfc6151.html
- https://github.com/ulid/spec
- https://github.com/ai/nanoid
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.