About SHA-256
SHA-256 is part of the SHA-2 family published by NIST in FIPS 180-4. It is used in TLS certificates, Git (newer object format), Bitcoin, code signing and Subresource Integrity. No practical collision attack is known.
How it works here
SHA-1 and the SHA-2 family are computed with the browser's Web Crypto API (crypto.subtle.digest). MD5 is not part of Web Crypto, so it is computed with a small JavaScript implementation of RFC 1321. Text is hashed as UTF-8 bytes.
Known values to check against
| Input | Algorithm | Hash |
|---|---|---|
| (empty) | MD5 | d41d8cd98f00b204e9800998ecf8427e |
| (empty) | SHA-256 | e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
| hello world | MD5 | 5eb63bbbe01eeed093cb22bb8f5acdc3 |
| hello world | SHA-1 | 2aae6c35c94fcfb415dbe95f408b9ce91ee846ed |
| hello world | SHA-256 | b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 |
Which hash should I use?
| Algorithm | Output | Status |
|---|---|---|
| MD5 | 128 bits / 32 hex | Broken for security; fine for non-adversarial checksums |
| SHA-1 | 160 bits / 40 hex | Collisions demonstrated (2017); avoid for signatures |
| SHA-256 | 256 bits / 64 hex | Current standard choice |
| SHA-384 | 384 bits / 96 hex | Truncated SHA-512, used in TLS suites and SRI |
| SHA-512 | 512 bits / 128 hex | Faster than SHA-256 on 64-bit CPUs |
For storing passwords use a slow, salted algorithm such as Argon2, scrypt or bcrypt, never a plain fast hash.