An Introduction to Encryption and Hashing
Published on 1st August 2025 by Phil
Hashing and encryption hide data with one key difference - encryption is reversible, whereas hashing is not - in the ideal. Hashing is also deterministic - the same input always produces the same output.
Hashing is used for integrity verification, a typical use case for hashing is passwords - rather than store someone's password directly, we run it through a hashing algorithm to hide it, for instance, the code below always returns the same hash for the word 'password' (deterministic).
echo hash('sha256', 'password'); 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
Therefore, in the database, we would store '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8' rather than your password and when you log in and submit your password, we hash it with the same algorithm and check the hashes match, if they do you can be authenticated.
In reality, you would also add SALT to the hash - a SALT is a random string to make it increasingly difficult to reverse, especially by the technique of mapping common words and phrases to their hashes (a downside of being deterministic). For instance, hashing the word `password` with SHA256 (opens in new tab) always creates the string `5e884...d1542d8` and therefore there's no need to even attempt to reverse the hash, you just need a table which maps common words like `password` to their hash `5e884...d1542d8` and hey presto, if you know the hash, you know the password. The SALT is therefore important as it changes the hash, and as it's always used and appended to the password, it's again deterministic but more importantly much more secure.
echo hash('sha256', 'password'.'some random salt'); dcd23593efddc05c233682b86f7f7c23c7b961d80c5d50fc83381af5acd4fb55
Encryption on the other hand is for confidentiality - for instance, when we want to store data and we don't want people to be able to read the data while it is at rest (in storage), in this case, we encrypt the data and place it in storage and decrypt it on retrieval.
Another typical example is we want to transfer data from one place to another and prevent people who intercept the message while it's in transit from being able to read the contents. So the sender encrypts the data with a key, the data is sent and the receiver decrypts the data with another key. Both the sender and receiver need a key to decrypt the data.
That's the very basics of encryption and hashing.
How Does My-Beacon Work?
Published on 6th October 2025 by Debs
I love watching Phil head off on another adventure on his motorbike. But every time, there's always the worry that if something happens to him, how would anyone let me know?
To help alleviate that worry, we created My-Beacon, a QR code service ....
Warning Beacons of My-Beacon
Published on 20th August 2025 by Phil
Inspired by the Warning Beacons of Gondor from Lord of the Rings, we bring you the Warning Beacons of My-Beacon! Beacon for short!
Beacons have been used over the centuries mainly to raise the alarm...
An Introduction to Encryption and Hashing
Published on 1st August 2025 by Phil
Hashing and encryption hide data with one key difference - encryption is reversible, whereas hashing is not - in the ideal. Hashing is also deterministic - the same input always produces the same output.
Hashing is used for integrity verificat...