Tool 1 of 8

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.

Your challengeFind out why a website shows a long "SHA-256" code next to a download, and why that code alone does not stop every attacker.
Visualise

What a hash function does

Genuine SHA-256
Input (any size)
Hello
SHA-256hash function
Hash value (always 64 hex characters)
(not computed yet)
Experiment

Hash lab

Genuine
Hash function:
Current hash
Reference hash (pinned earlier, differences highlighted in the current hash)
(press "Pin as reference")

Try this

Tip: pin a hash, then change the input. How many hex characters stay the same?

Experiment

Scenario: is this download genuine?

Genuine hashing Simulated website and attacker
downloads.example-software.test
Official download page (simulated)

photo-editor-setup.exe (4 KB demo file)

SHA-256 published on the page
File you received
(choose a file on the right)
SHA-256 you computed from the received file
(not computed yet)

Which file arrives?

The file is read inside your browser only. It is never uploaded.

Experiment

Scenario: storing passwords

Genuine SHA-256 and PBKDF2

A website must check passwords without keeping them in clear text. It stores a hash instead. But which hash matters a lot.

UserPassword (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.

Explain

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

HashingEncryption
GoalCreate a fingerprint to check integrityHide the content (confidentiality)
KeyNoneYes, a secret key is needed
Reversible?No, one-wayYes, with the right key (decryption)
Output lengthAlways the sameGrows with the input

Common misconceptions

"Hashing encrypts my password."
Nothing is encrypted. There is no key and no way to decrypt; the site compares hashes.
"SHA-256 is fine for passwords."
It is far too fast: attackers test billions of guesses per second. Use a slow, salted algorithm such as Argon2, bcrypt or PBKDF2.
"If the hash matches, the file is safe."
It only means the file equals the one the hash came from. If an attacker can replace the hash too, the check proves nothing.
"Similar inputs give similar hashes."
The avalanche effect makes them look completely different.

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.

Apply

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
All three are completely different. This is the avalanche effect: hash functions are sensitive to every single bit, including case and invisible spaces.
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
SHA-256 always gives 64 hex characters (256 bits), SHA-512 always 128 (512 bits). The length depends on the hash function, never on the input.
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
No. The attacker replaced both the file and the hash. You need a reference that the attacker cannot change: a hash from a separate trusted source, an HMAC with a secret key (Tool 2), or a digital signature from the publisher (Tool 7).
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?

Show answer
SHA-256 allows hundreds of thousands of guesses per second even in a browser (billions on a graphics card); PBKDF2 with 600 000 iterations allows only a few. The salt also makes two identical passwords produce different stored values, so attackers cannot use precomputed tables.

Continue the journey