What a cryptographic hash is
A cryptographic hash function turns any input, a word or a whole disk image, into a short fixed-size value called a digest. SHA-256 always produces 32 bytes, usually written as 64 hex characters.
Three properties make a hash useful for security. It is one-way: you cannot work back from the digest to the input. It is collision-resistant: nobody can find two inputs with the same digest. And it is sensitive: change one bit of the input and about half the bits of the digest change.
SHA-256("acme") = 822b33ad87c148a0a20a5ba7cd5ebcaa68d36a18e7aad165554903f52ca82757
SHA-256("acme.") = fb97486b1225cfac7929ed75e7a08a4ad6c3488176f0b59d0a861f2e2925d4e3The SHA family at a glance
This tool computes four hashes at once, all defined in the US standard FIPS 180-4 and built into every browser through Web Crypto.
| Algorithm | Digest size | Hex length | Status |
|---|---|---|---|
| SHA-1 | 160 bits (20 bytes) | 40 | Broken for collisions; legacy use only |
| SHA-256 | 256 bits (32 bytes) | 64 | The common default |
| SHA-384 | 384 bits (48 bytes) | 96 | SHA-512 truncated, with different start values |
| SHA-512 | 512 bits (64 bytes) | 128 | Often faster than SHA-256 on 64-bit CPUs |
SHA-256, SHA-384 and SHA-512 are the SHA-2 family. SHA-3 is a separate, newer design; browsers do not offer it through Web Crypto, so it is not here.
Why SHA-1 is marked legacy
In 2017 researchers published two different PDF files with the same SHA-1 digest. Since then, attacks have become cheaper, and chosen-prefix collisions, which let an attacker shape both inputs, have been demonstrated too. SHA-1 must not be used for signatures or certificates.
SHA-1 still appears in older systems: Git object ids, some certificate fingerprints shown by tools, and HMAC-SHA1 in one-time passwords. HMAC-SHA1 is a different case and is still considered secure as a MAC, but new designs should use SHA-256.
Where hashes show up in identity systems
Hashes appear in almost every part of OAuth, OpenID Connect and SAML, usually inside something else.
Token signatures
The number in a JWT algorithm name is the hash: RS256 is RSA with SHA-256, ES384 is ECDSA with SHA-384, HS512 is HMAC with SHA-512. The token is hashed and the hash is signed.
PKCE
The PKCE code challenge with method S256 is the Base64url encoding of the SHA-256 hash of the code verifier. Keycloak can require PKCE per client, and the S256 method is the one to use.
Token hashes in ID tokens
OpenID Connect ID tokens can carry at_hash and c_hash: the left half of the hash of the access token or authorization code, Base64url-encoded, with the hash matching the token’s signing algorithm. They bind the ID token to the other token.
Certificate fingerprints and key ids
A certificate fingerprint is a hash of the certificate’s DER bytes. The x5t#S256 header in a JWT is the SHA-256 thumbprint of a certificate, and an RFC 7638 JWK thumbprint is the SHA-256 hash of a key’s required members. The certificate decoder shows fingerprints.
Why plain hashes are wrong for passwords
A hash is designed to be fast. That is a feature for checking files and a flaw for storing passwords. A modern GPU computes billions of SHA-256 hashes per second, so an attacker with a stolen table of password hashes can test every common password, and many uncommon ones, very quickly.
Unsalted hashes are worse still. The same password always has the same hash, so one precomputed table cracks every account that used it, and identical hashes reveal which users share a password.
Passwords need a function built to be slow and salted: Argon2, scrypt, bcrypt or PBKDF2. OWASP’s Password Storage Cheat Sheet recommends Argon2id first. Keycloak stores passwords with such functions, configured per realm through the password policy.
Never store passwords as SHA-1, SHA-256 or MD5, with or without a salt. A salt stops precomputed tables but does nothing about speed.
What this tool does and does not do
- It hashes text as UTF-8 bytes, or bytes you give as hex or Base64.
- It shows SHA-1, SHA-256, SHA-384 and SHA-512 at once, in hex, Base64 or Base64url.
- It uses the browser’s Web Crypto API; the input never leaves the page.
- It does not hash files. For a file, use
sha256sumorshasum -a 256on the command line. - It does not offer MD5 or SHA-3, which Web Crypto does not provide.
How to hash text
- Choose the input format: text, hex or Base64.
- Type or paste the input. Every character counts, including spaces and line breaks.
- Choose the output format: hex for most tools, Base64 or Base64url where a protocol expects it.
- Copy the digest you need.
Why your hash might not match
If this tool and another give different digests for the "same" input, the input bytes differ. The usual causes:
- A trailing line break.
echo "acme" | sha256sumhashesacmeplus a newline; useecho -norprintf. - A different encoding. Non-ASCII text hashed as UTF-16 or Latin-1 gives other bytes than UTF-8.
- Hex read as text. The text
00ffis four bytes; the hex00ffis two. - Line endings. Windows files use CRLF, so a copied block may hash differently than the file.
- Output encoding. The same digest looks different in hex and Base64; compare in one format.
printf '%s' 'acme' | sha256sum
printf '%s' 'acme' | openssl dgst -sha256 -binary | base64Security notes
- Hashing personal data such as emails or phone numbers is not anonymization. The inputs are guessable, so the hashes can be reversed by trying candidates.
- A hash proves integrity only if the expected hash comes from a trusted place. A download page that serves both the file and its hash can be changed in both places.
- To prove who made a message, use an HMAC or a signature, not a bare hash. Anyone can compute a hash.
- Compare secrets and MACs in constant time on servers, so timing does not leak how many bytes matched.
Best practices
- Use SHA-256 or longer for new work.
- Keep SHA-1 to reading legacy values, never to new signatures or certificates.
- Use a password hashing function for passwords, an HMAC for authenticity, and a signature for public verifiability.
- State the encoding wherever you exchange digests: hex or Base64, and the exact input bytes.
Checking a download with a checksum
The most common everyday use of a hash is checking that a file arrived intact. Projects publish a checksum file next to each release, listing the SHA-256 of every artifact.
- Download the file and the checksum file from the official release page.
- Compute the SHA-256 of the file locally with
sha256sum fileon Linux orshasum -a 256 fileon macOS. - Compare the two values. They must match character for character.
- Where the project signs its checksum file, verify that signature too. A matching hash only proves the file matches the list; the signature proves the list came from the project.
Container images work the same way. An image digest such as sha256:... is the hash of the image manifest, so pinning an image by digest instead of a tag guarantees you run exactly the bytes you tested. That is a good habit for an identity server: pin the Keycloak image you upgraded and tested, rather than a moving tag.