Hash functions: MD5, SHA-1, SHA-256
What a cryptographic hash is, how the common algorithms differ, and why MD5/SHA-1 are retired for security.
What a hash function does
A cryptographic hash function takes input of any size and returns a fixed-length fingerprint (the digest). Good properties: deterministic (same input β same output), fast to compute, and preimage-resistant (you cannot reverse it) and collision-resistant (you cannot find two inputs with the same digest).
sha256("hello") =
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824MD5, SHA-1, SHA-256 compared
| Algorithm | Digest | Status |
|---|---|---|
| MD5 | 128-bit | Broken β collisions are trivial; never use for security. |
| SHA-1 | 160-bit | Broken β collision found in 2017; deprecated for signatures. |
| SHA-256 | 256-bit | Current standard (SHA-2 family); safe for integrity & signatures. |
| SHA-3 / BLAKE3 | variable | Modern alternatives; BLAKE3 is very fast. |
β οΈ
A hash proves integrity (data unchanged), not authenticity. To verify the sender you need a keyed MAC (HMAC) or a signature.
Hashing passwords is different
Plain SHA-256 is not enough for passwords: it is too fast, so attackers brute-force it cheaply. Password hashing needs to be slow and salted β use bcrypt, scrypt, Argon2, or PBKDF2.
# DO NOT: hash = sha256(password) # fast, unsalted
# DO: a slow, salted KDF
import hashlib, secrets
pwd = b'correct horse battery staple'
salt = secrets.token_bytes(16)
dk = hashlib.pbkdf2_hmac('sha256', pwd, salt, 200000)
# store salt + dk; verify by recomputingFAQ
Can I decrypt a SHA-256 hash?
No. Hashing is one-way. You can only check a guess by hashing it and comparing.
Is SHA-256 collisions possible?
Not practically. Finding one would require about 2^128 work β far beyond reach.
Related
Checksums & verifying files Base64 encoding
Last refreshed 2026-09-17.