Hashing
A hash function turns any data into a short, fixed-length fingerprint. The same data always gives the same fingerprint, and the smallest change gives a completely different one.
What a hash function does
Genuine SHA-256Hash lab
GenuineTry this
Tip: pin a hash, then change the input. How many hex characters stay the same?
Scenario: is this download genuine?
Genuine hashing Simulated website and attackerOfficial download page (simulated)
photo-editor-setup.exe (4 KB demo file)
Which file arrives?
The file is read inside your browser only. It is never uploaded.
Scenario: storing passwords
Genuine SHA-256 and PBKDF2A website must check passwords without keeping them in clear text. It stores a hash instead. But which hash matters a lot.
| User | Password (never stored) | What the database stores |
|---|
Log in as Lea
Storage method
Real systems use slow, salted algorithms such as Argon2, bcrypt or PBKDF2. PBKDF2 is the one built into browsers, so it is used here.
Key ideas
Fixed length
A word, a book or a film: SHA-256 always produces 256 bits, written as 64 hexadecimal characters.
Deterministic
The same input always gives exactly the same hash, on any computer. That is what makes comparison possible.
Avalanche effect
Change one character and about half of the output bits change. The new hash looks completely unrelated.
One-way
You cannot compute the input from the hash. The only way back is to guess inputs and compare their hashes.
Collision resistant
Finding two different inputs with the same SHA-256 hash is practically impossible. Old functions such as MD5 and SHA-1 lost this property and must not be used for security.
No key
A hash function has no secret key. Anyone can compute the hash of anything, including an attacker.
Hashing is not encryption
| Hashing | Encryption | |
|---|---|---|
| Goal | Create a fingerprint to check integrity | Hide the content (confidentiality) |
| Key | None | Yes, a secret key is needed |
| Reversible? | No, one-way | Yes, with the right key (decryption) |
| Output length | Always the same | Grows with the input |
Common misconceptions
Limitations
A hash proves integrity only if the reference hash comes from a trusted source. It says nothing about who created the data. Tool 2 (HMAC) and Tool 7 (signatures) solve this.
Short or common inputs (like passwords or "yes"/"no") can be found by guessing, even though the function is one-way.
Where you meet hashing
Download verification
Linux images and software often publish a SHA-256 checksum. On Windows, Get-FileHash file.iso computes it; on Linux, sha256sum file.iso.
Password storage
Websites and operating systems store slow, salted password hashes, never the passwords themselves.
Malware detection
Antivirus and threat-intelligence services identify known malware by the hash of the file.
Digital forensics
Investigators hash a seized disk image to prove later that the evidence was not changed.
Digital signatures
Signatures are computed over the hash of a document. See Tool 7.
Git
Every Git commit is identified by a hash of its content, so history cannot be silently changed.
Challenges
1. Same or different?
Hash Password, password and password (with a space) in the hash lab. Are any two hashes alike? Which property did you just observe?
Show answer
2. Fixed length
Hash an empty input and then the 100 000-character input. Count the characters of each hash. What do you notice? Then switch to SHA-512.
Show answer
3. The compromised website
In the download scenario, choose "Attacker controls the website". The hashes match. Is the file genuine? What would you need to be sure?
Show answer
4. Why not just hash passwords with SHA-256?
Run "Measure speed". How many password guesses per second could an attacker test against SHA-256 on your computer, and against PBKDF2?