SHA-256 开发者指南:校验和、HMAC 与边界
何时该用 SHA-256(何时不该)、HMAC 加密钥的意义、密码为何要用 KDF。
SHA-256 is the fingerprint function of the internet — embedded in TLS certificates, package managers and blockchains. Yet it is also the most misused primitive in application code. This guide draws the usable line.
What SHA-256 is good for
- Integrity: compare a download hash with the published one — same fingerprint, same bytes.
- Cache and dedup keys: arbitrary content maps to a stable 64-character hex identifier.
- Signature inputs: JWT HS256 and RSA/ECDSA signatures all hash with SHA-2 underneath.
Generate any digest offline with the SHA-256 Hash Generator — nothing you paste leaves the browser, which matters when hashing URLs or internal identifiers.
What hashing cannot do
A hash is one-way and unkeyed. It provides no confidentiality (anyone sees it) and no authentication (anyone can compute it). Encrypting something is a different operation with a key; hashing it merely fingerprints it.
HMAC: hashing with a secret
HMAC wraps SHA-256 with a key: only holders of the secret can produce a matching tag. That is what turns a plain digest into a verifiable signature — the mechanism behind JWT HS256 and most API request signing. Decode a JWT and inspect its signature claims with the JWT Decoder.
Passwords: do not use SHA-256 directly
Fast hashes are build for speed — exactly what attackers exploit with GPU cracking. Password hashing needs deliberately slow, salted KDFs: bcrypt, scrypt or Argon2. Generate strong random passwords instead of hashing weak ones, using the Password Generator.
Quick checksum workflow
After downloading a binary, generate its SHA-256 locally and compare character by character with the vendor value — the hash tool does it in one paste, including large inputs.
相关指南
文中提到的工具
SHA-256 Generator
Compute the SHA-256 digest of any text instantly — with SHA-1, SHA-384 and SHA-512 alongside. Uses WebCrypto when available, with a pure-JS fallback. Includes HMAC demo mode.
Open tool →JWT Decoder
Decode a JWT header and payload into readable JSON with formatted dates for exp/iat/nbf, signature state and expiry status. Safe: verification never happens in the browser.
Open tool →Password Generator
Generate cryptographically strong passwords with adjustable length and character sets, ambiguous-character filter and entropy readout. Five candidates at a time, 100% offline.
Open tool →