About
hashgen was created and is maintained by the YouTube channel The Seasoned Programmer. Questions or suggestions? Email info@the-seasoned-programmer.com.
Every tool on this site runs in your browser. Your text, files and keys are never sent to a server. The hashes come from the audited, open-source noble-hashes library, because browsers' built-in Web Crypto API only offers SHA-1 and SHA-2.
What hashes are used for
- Checking downloads: a project publishes the SHA-256 of each file, you hash your copy, and if they match the file arrived intact and unchanged.
- Digital signatures and certificates: a signature is made over a hash of the document, not the whole document.
- Content addressing: Git names every commit and file by its hash, and Docker images, IPFS and many caches do the same.
- Message authentication: an HMAC proves a message came from someone holding a shared key and wasn't changed on the way.
- Blockchains: Bitcoin uses SHA-256 and RIPEMD-160; Ethereum uses Keccak-256.
Which algorithm should I use?
- SHA-256 is the safe default: supported everywhere and with no known weaknesses.
- SHA-512 is often faster than SHA-256 on 64-bit machines and gives a longer hash.
- SHA-3 is built differently from SHA-2, which makes it a good hedge if SHA-2 is ever weakened.
- BLAKE2 and BLAKE3 are very fast in native code and just as secure. BLAKE3 can use every CPU core on large files.
- MD5 and SHA-1 are broken for security: attackers can make two different files with the same hash. Use them only when a system you talk to requires them, or for non-security checks.
- CRC-32 isn't a cryptographic hash at all. It catches random transmission errors, which is why zip, PNG and Ethernet use it, but anyone can forge it.
How HMAC works
A plain hash can be recomputed by anyone, so it can't prove who sent a message. HMAC (RFC 2104) mixes a secret key into the hash in two passes: H((K ⊕ opad) ‖ H((K ⊕ ipad) ‖ message)). Only someone who knows the key can make the right code, and the two-pass design avoids the length-extension attacks that a simple H(key ‖ message) suffers from. Webhooks from GitHub, Stripe, Slack and Shopify, AWS request signing and JWTs with HS256 all use HMAC.
When you check an HMAC in your own code, compare it with a constant-time comparison such as crypto.timingSafeEqual or hmac.compare_digest, not ==.
Hashes are not for passwords
Fast hashes like SHA-256 are the wrong tool for storing passwords: a graphics card can try billions of guesses a second. Use a password hash that is deliberately slow and salted, such as Argon2id, scrypt, bcrypt or PBKDF2 with a high iteration count.
Standards
- FIPS 180-4: SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.
- FIPS 202: SHA-3 and SHAKE.
- RFC 1321: MD5. RFC 7693: BLAKE2.