Security Tools
Hash Functions Explained: MD5, SHA-1, SHA-256
Understand cryptographic hash functions, their properties, and when to use each algorithm.
A cryptographic hash function takes input of any size and produces a fixed-size output (hash) that appears random. Even a tiny change produces a completely different hash.
Key Properties
- Deterministic: Same input always produces same hash
- Fast computation: Efficient for any input size
- Pre-image resistance: Can't reverse a hash to find the input
- Collision resistance: Extremely unlikely for two inputs to produce the same hash
Common Algorithms
MD5 (128-bit): Broken for security. Still useful for checksums.
SHA-1 (160-bit): Deprecated since 2017. Don't use for new projects.
SHA-256 (256-bit): Currently secure. Used in blockchain and certificates.
SHA-512 (512-bit): Strongest common option. Slightly faster than SHA-256 on 64-bit systems.
Password Hashing
Never store passwords with plain hash functions. Use bcrypt, scrypt, or Argon2 instead. These are intentionally slow and use salt to resist attacks.
Frequently Asked Questions
Can two inputs produce the same hash?
Theoretically yes (collision), but for SHA-256 the probability is so low it's practically impossible.
Is MD5 safe?
Not for security purposes. MD5 has known collision attacks. Still OK for non-security checksums.
Hashing vs encryption?
Hashing is one-way (can't reverse). Encryption is two-way (can decrypt with key). Hashes verify data; encryption provides confidentiality.
