โ Back to Hashing vs encryption
๐ฅฉ Hashing vs encryption: cheat sheet
๐จ The analogyA meat grinder versus a locked suitcase: mince never turns back into steak, but the suitcase opens with its key.
๐ The regular explanationHashing is a one-way, fixed-size fingerprint of data, used for integrity checks and (slowly, with salt) for passwords; encryption is reversible with a key, used to keep data secret. HMACs and signatures add proof of who sent it, and Base64 is neither.
- The cook puts a steak in the grinder and out comes a patty of mince. The same steak always makes exactly this patty.
- Try to turn the patty back into the steak. It can't be done, so the grinder only goes one way.
- The cook packs something into the suitcase and locks it. From the outside, nobody can see what's in it.
- The friend with the key opens the suitcase and gets back exactly what was packed.
- The butcher grinds the steak and pins a photo of the patty on the shop's noticeboard for everyone to see.
- The van brings the steak. The restaurant grinds it, and the patty matches the photo, so nothing was swapped.
- Next time the van driver swaps in a different steak. The restaurant grinds it and the patty looks nothing like the photo, so it's sent back.
- The check only works because the photo came straight from the butcher. If the driver could swap the photo too, it would prove nothing.
- Ana signs up with her secret steak. The chef runs it through a fast grinder and keeps only the patty in the fridge.
- Ben happens to own the very same steak, so his patty is identical to Ana's. Anyone looking at the fridge can see they match.
- A thief steals the fridge. With a book of patties from every common steak, already ground, he finds a match for both in seconds.
- The chef switches to a slow hand grinder and adds a pinch of each person's own spice, written on the label. Now Ana's and Ben's patties differ.
- The thief steals this fridge too, but his book is useless. He must crank the slow grinder for every guess, once for each person.
- The butcher and the restaurant share a spice nobody else has. The butcher grinds the steak with it and tapes the spiced patty to the box.
- The restaurant grinds the steak with the same spice. The patties match, so it's untouched and really from the butcher.
- The crook swaps in a cheaper steak and grinds a new patty, but without the spice it can't match. The restaurant refuses it.
- You and your friend hold copies of the same key. You set the dial to a fresh number, lock the suitcase, add a tamper seal and leave it in the luggage room.
- Your friend fetches it, sees the seal is whole and opens it with the same key.
- Someone in the luggage room tampers with the suitcase. Your friend sees the broken seal and refuses what's inside.
- You lock a second suitcase but forget to change the dial. With two suitcases on the same number, a snoop can learn what's in both and fake a seal.
- Bob keeps his only key and hands out open padlocks to anyone who asks, including the porter.
- Ana snaps a padlock shut on her suitcase and sends it. The porter carries it but can't open it, even though he has padlocks too.
- Only Bob's own key opens the padlock, so Bob opens the suitcase.
- Bob replies with a note pressed with his wax seal. Ana checks it against the seal picture Bob handed out with his padlocks, so she knows it's his and untouched.
๐งฉ Key questions
- The kitchen must keep a customer's card and later hand it to the bank, which must read it. Grinder or suitcase?
- The suitcase, because the delivery firm needs the real thing back with the key. Mince never turns back into steak, and wrapping paper hides nothing. Only the suitcase gives the original back.
- Ana and Ben own the same steak. Why should the chef add each person's own spice before grinding?
- So their patties differ and a thief's book of pre-ground patties is useless. The spice is written on the label, so it isn't secret. It just makes every patty unique.
- Why does the chef use a slow hand grinder for regulars' steaks instead of the fast electric one?
- One slow check is fine at the door, but a thief's millions of guesses take far too long. Speed helps the thief, not you. Making each turn costly hurts him millions of times over.
- A crook on the road swaps the steak and grinds a fresh patty to tape on the box. What stops him?
- A spice only the butcher and restaurant share, which the crook can't add. Anyone can grind a plain patty, even a bigger one, but only the two of them can make the spiced one.
- You lock two suitcases with the same key and the same dial number. What goes wrong?
- A snoop comparing the two can learn a lot about what's inside, and fake a seal. The dial must be a fresh number every single time you lock with that key.