What's the Purpose of Hashing?
The main purpose of hashing is to ensure data integrity—to verify that data hasn't been tampered with.
Every piece of data, when hashed, produces a unique string known as a hash value or digest. This acts like a digital fingerprint. Even the smallest change in the data will create a completely different hash.
This makes hashing incredibly useful when sending data over insecure networks like the internet. By comparing the original hash to the received hash, we can confirm whether the data has been altered during transmission.
A Simple (and Slightly Awkward) Example
Let's say we're about to meet for lunch. Before I leave, I suddenly recall... last time, things were great—but your body odor wasn't.
So I decide to send you a friendly reminder:
Message: "Please wear deodorant."
Before sending it, I run this sentence through the SHA-256 hash function. The result:
33ebb528eab107766343d0ac591952bb68ee959d45b7a8b399628e662f3bc1ef
I send you the hash first, and then the actual message.
When you receive the message, you might think:
"Wait... Did they really send this? Or was the message intercepted and changed on the way?"
To find out, you run the message you received through the same hash function.
If the hash you get matches the one I sent earlier, then:
- The message hasn't been altered.
- It's legit (and yes, maybe your armpits need some love).
- The hash confirms the message's integrity.
Note: In real applications, hashes are typically protected during transmission—but we'll cover that in a later lesson.
Real-Life Use Case: Email Passwords
You may not realize it, but you encounter hashing every day—like when you log into your email.
Most email providers don't store your actual password. Instead, they store a hashed version of it.
Here's how it works:
- You create an account and enter your password.
- That password is hashed and stored—not the plain text.
- When you log in later, your entered password is hashed again.
- If the new hash matches the stored one, access is granted.
Why Not Store Actual Passwords?
If companies stored your password in plain text, and a hacker broke into the system, your real password could be stolen—especially dangerous if you use that password on multiple sites.
By storing only the hashed password, even if a hacker accesses the database, all they get are unreadable hashes.
Since hash functions are one-way and irreversible, the hacker can't figure out the original password from the hash alone.
Recap: Why Hashing Matters
- Verifies data integrity by detecting changes.
- Protects sensitive info, like passwords.
- Produces a fixed-length output, no matter the size of the input.
- Cannot be reversed, keeping your data safe.
Hashing ensures that even if someone gains access to stored information, it's scrambled and useless without the original input.
