Three cryptographic primitives show up in nearly every web application: hash functions, universally unique identifiers (UUIDs), and random passwords or API tokens. They look superficially similar — all three produce strings of letters and digits — which leads to costly mistakes: storing user passwords with plain SHA-256, using UUID v4 as a secret reset token, or indexing billions of database rows on random keys that shred B-tree cache performance. This guide explains what each primitive does, which modern variant to pick, and where security boundaries lie.
Cryptographic hash functions
A cryptographic hash function maps arbitrary input bytes to a fixed-size digest (fingerprint). Good hashes share three properties: deterministic (same input always yields the exact same digest), avalanche effect (changing a single bit scrambles half the output bits), and one-way / collision-resistant (infeasible to reconstruct the input or find two different inputs with the same digest).
SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA-256("hello.") = 1791188a1c689643d18d718d3e3f98f46c98982c05c4529508c7098c973e5563
Use SnipFerry’s Hash Generator to calculate SHA-256, SHA-384, SHA-512, SHA-1, and MD5 digests simultaneously in your browser (UTF-8 encoded, never uploaded).
| Algorithm | Output size | Security status | Appropriate uses |
|---|---|---|---|
| SHA-256 / SHA-384 / SHA-512 | 256–512 bits (64–128 hex) | Secure | File checksums, content-addressed storage, digital signatures, HMAC |
| BLAKE3 / SHA-3 | 256+ bits | Secure (modern) | High-throughput file verification, build caches, integrity proofs |
| SHA-1 | 160 bits (40 hex) | Collision-broken (SHAttered, 2017) | Legacy Git repositories & old integrations only |
| MD5 | 128 bits (32 hex) | Severely broken | Non-adversarial ETags, deduplication & legacy checksums only |
Why you must NEVER hash passwords with SHA-256
SHA-256 was engineered to run as fast as possible — modern GPUs compute tens of billions of SHA-256 hashes per second. If an attacker steals a database containing plain SHA-256 password hashes (even salted), they can brute-force weak and medium passwords at industrial speed.
Instead, store passwords with a deliberately slow, memory-hard, salted Key Derivation Function (KDF):
- Argon2id (current OWASP #1 recommendation) — resists both GPU and ASIC cracking by requiring configurable RAM as well as CPU time.
- scrypt — memory-hard alternative built into Node.js (
crypto.scrypt) and Go. - bcrypt — battle-tested fallback (watch its 72-byte input truncation limit).
Similarly, when authenticating webhooks or API requests with a shared secret, never compute SHA-256(secret + body) (vulnerable to length-extension attacks on SHA-256). Always use HMAC-SHA256 and compare digests with a constant-time comparison function (crypto.timingSafeEqual).
UUIDs: Version 4 vs Version 7 (RFC 9562)
A UUID is a 128-bit identifier formatted as 32 hexadecimal digits in five hyphenated groups (36 characters total): 01936f8a-2c1e-7e2f-a6c1-5d0b8e7f4a92. Distributed services can mint UUIDs independently without hitting a central database sequence, and collision probability is astronomically low. RFC 9562 (published in 2024) defines the modern landscape:
| Version | Structure | Sort order | Best use case |
|---|---|---|---|
| UUID v4 | 122 random bits + 6 version/variant bits | Completely random | Opaque public IDs where creation time must stay hidden |
| UUID v7 | 48-bit Unix millisecond timestamp + 74 random bits | Monotonically time-ordered | Database primary keys (PostgreSQL, MySQL) — fast sequential B-tree inserts |
| UUID v5 | Deterministic SHA-1 hash of namespace + name | Deterministic | Reproducible IDs derived from a URL or natural key |
| Nil UUID | 00000000-0000-0000-0000-000000000000 | Sentinel | Null/placeholder ID in typed schemas & tests |
Why did databases adopt UUID v7 so quickly? Inserting random UUID v4 primary keys into a large B-tree index forces random writes across scattered disk pages, causing page splits and cache churn. UUID v7 appends new rows to the right edge of the index just like auto-incrementing integers while staying globally unique. Generate v4, v7, or Nil UUIDs in bulk with SnipFerry’s UUID Generator.
Important security note: UUIDs are identifiers, not secrets — especially UUID v7, whose first 48 bits reveal the exact creation millisecond! Never use a UUID v7 as a session token, API key, or password-reset token.
Password & token entropy: math that actually matters
Guessing resistance depends on entropy, measured in bits: entropy = length × log₂(pool_size). Every single additional bit doubles the number of guesses required:
| Secret type | Pool size | Entropy | Verdict |
|---|---|---|---|
8 lowercase letters (a-z) | 26 | ~38 bits | Weak — cracked in minutes on a single GPU |
12 mixed alphanumeric (A-Za-z0-9) | 62 | ~71 bits | Acceptable for rate-limited logins, low for offline secrets |
| 16 characters, letters + digits + symbols | ~90 | ~104 bits | Strong for primary accounts & password managers |
| 20 characters, full set without look-alikes | ~82 | ~127 bits | Excellent — effectively uncrackable offline |
| 32-byte random API key (base64url / hex) | 256/byte | 256 bits | Standard for bearer tokens, webhook secrets & HS256 keys |
Where randomness comes from matters just as much as length. Never generate passwords or tokens with Math.random(), which is a predictable PRNG. SnipFerry’s Password & Random String Generator uses the browser’s hardware-backed CSPRNG (crypto.getRandomValues()) with rejection sampling so every character has uniform probability, and lets you exclude look-alike characters (0/O, 1/l/I) without sacrificing cryptographic strength. Store unique passwords in a password manager and enable two-factor authentication everywhere. Working with signed auth tokens too? Read JWT Explained and Base64 Explained.