Hashing Basics
This is a short, clear guide to the essentials of hashing, for anyone learning cybersecurity or cryptography.
This is a short, clear guide to the essentials of hashing, for anyone learning cybersecurity or cryptography.
What is a Hash?#
A hash is a fixed-length string produced by a hash function from any size input.
- Input → Hash Function → Fixed-size Hash Value
- Same input → always same hash.
- Small input change → completely different hash.
Example Hash Algorithms:
- MD5 (insecure)
- SHA-1 (insecure)
- SHA-256 (recommended)
Why Use Hashing?#
** File Integrity Checking**
- Check if downloaded file matches original.
- Compare hashes:
- If hashes match → files identical.
- If hashes differ → something changed (corruption or tampering).
Example:
sha256sum file.isoPassword Storage Never store passwords in plaintext. Store hashes instead. When user logs in: Hash the entered password. Compare to stored hash.
Example:
User password → hash function → stored hashData Integrity & Signatures Hash data before signing it. Receiver verifies signature and hash.
Hash Properties#
Deterministic Same input → same output. Quick to Compute Fast even on large files. Pre-Image Resistance Hard to find input from hash. Collision Resistance Hard to find two inputs with same hash. Avalanche Effect Small input change → huge output change.
Collisions#
Collision = two different inputs with same hash. Good hash functions make collisions extremely rare. MD5 and SHA-1 are no longer collision-resistant. Avoid them.
Recognizing Hashes#
Length hints at algorithm: MD5: 32 hex chars. SHA-1: 40 hex chars. SHA-256: 64 hex chars.
Example:
SHA-256 hash
9b74c9897bac770ffc029102a200c5deCracking Hashes Hashes are not encryption → they can't "decrypt". To crack a hash → guess input → hash it → compare. Attack Methods Brute Force Dictionary Attacks Rainbow Tables
Popular Tools#
John the Ripper Hashcat
Hashing for Integrity Protection Publish file + its hash. User computes their own hash. If it matches → file is untampered.
Example:
Website offers file.zip and file.zip.sha256 You download both and run:
sha256sum -c file.zip.sha256Summary#
Hashing ensures data integrity. Used in password storage, signatures, file verification. Secure hash functions resist collisions and pre-image attacks. Always choose modern algorithms like SHA-256 or better.