Level 3 · How it worksThe village#186

Encryption vs hashing: a locked box opens again, a wax seal never turns back into the letter

Encryption scrambles data so that someone with the key can turn it back. Hashing makes a short, fixed-size fingerprint that can't be turned back at all. Bitcoin's notebook uses hashes and signatures; the only encryption most users meet is the password on their wallet file.

Anna wants to send a letter to Grandma Rosa, who is staying in the next village. She puts it in a small box, locks it, and keeps one key while Rosa has the other. Anyone can carry the box. Only the two of them can open it and read the letter.

On the same day, Anna writes a line in the village notebook and presses a wax seal under it. Nobody can read the line from the seal. Nobody, not even Anna, can turn the seal back into the line. But anyone can check that the line and the seal belong together.

The box is encryption. The seal is hashing. One is built to be opened again, the other is built so that it never can be. Mixing them up is how people end up protecting the wrong thing.

What it is

Encryption turns readable data into gibberish that someone with the right key can turn back. The standard most of the world uses, AES, is described by NIST as "a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information", with keys of 128, 192 or 256 bits (FIPS 197).

Hashing turns any data into a short fingerprint of fixed size. There is no key and no way back. NIST's hash standard says the digests "are used to detect whether messages have been changed since the digests were generated" (FIPS 180-4).

One hides. The other proves nothing changed.

How it works

Take one short line and run it through both.

  1. The line. "Anna pays Rosa 5", 16 characters.
  2. Hashed with SHA-256. It gives 771a7b56bf877ff0779909045d4f67fb78d0a966c927eb06f018db158c329f55. That's 64 hexadecimal characters, which is 32 bytes.
  3. Change one character. "Anna pays Rosa 6" gives 9524a27a16ced42596d4d25eeacce06fd6d2de95f4db294a88a01542da71199c. Nothing in common with the first.
  4. Make it a hundred times longer. The same 16 characters repeated 100 times, 1,600 characters in all, give 67cb7ea1a06a58d64eccaf2ae215b45797db11450f58bc569b92972da31fa1f3. Still 32 bytes.

These hashes come from Python's standard hashlib library, and anyone can repeat them with the exact text above.

Now the box. AES works on "blocks of 128 bits", which is 16 bytes. Encrypt the 16-character line and you get at least 16 bytes of gibberish back. Encrypt the 1,600-character version and you get at least 1,600 bytes: 100 blocks. Encrypted data is as big as the original, because all of it has to come back out. A hash is the same size whatever you feed it, because nothing ever comes back out.

That's the quickest test you'll ever need. If the output is always the same size, whatever goes in, it can't be undone. If it keeps everything, someone with a key can read it.

Why it matters

  • Bitcoin's notebook isn't encrypted. Every amount and address sits in the open on every copy. What protects it is hashing (the seals that chain the pages) and signatures (proof that the owner agreed). Nothing on the ledger is waiting for a key.
  • Your wallet file may be encrypted. Bitcoin Core lets you encrypt a wallet with a passphrase. Its own documentation says "Only the wallet's private key is encrypted. All other wallet information, such as transactions, is still visible", and warns that "if the passphrase is lost, all the coins in the wallet will also be lost forever" (Bitcoin Core).
  • Websites should hash your password, not encrypt it. NIST's password guidance tells services to store passwords "salted with a random value and hashed, preferably using a computationally expensive algorithm" (NIST SP 800-63B-4). If they're hacked, the thief gets seals, not letters.

Where people get it wrong

  • "My bitcoin is encrypted on the blockchain." It isn't. It's locked by a signature rule, and the lock is public. Anyone can read the line, only the key holder can spend it.
  • "Hashing is a weak kind of encryption." It's not encryption at all. There's no key, so there's nothing to decrypt.
  • "A signature encrypts the message." A signature proves who agreed to a message. The message stays readable.
  • "An encrypted wallet is a backup." Encryption protects a file you have. It doesn't help if the file is lost, and a forgotten passphrase loses the coins with it.

The password reminder test

Here's one thing to check, on any website you use. Click "forgot password". If the site sends you your old password in an email, it was kept in a box it could open, or worse, in plain sight. A site that hashes properly can't tell you your password. It can only let you set a new one.

So the honest answer from a good website is "we don't know your password". It's the one time in tech where ignorance is the selling point.

Frequently asked questions

What is the difference between encryption and hashing?

Encryption scrambles data so that someone with the right key can turn it back into the original. Hashing turns data into a short fingerprint of fixed size that can't be turned back. Encryption hides information; hashing proves it hasn't changed.

Can a hash be decrypted?

No. A hash has no key and keeps only a fixed-size fingerprint, such as 32 bytes for SHA-256, whatever the input. Attackers can only guess inputs and compare the hashes, which is why short or common passwords are still at risk.

Is Bitcoin encrypted?

The Bitcoin ledger is not encrypted: amounts and addresses are public on every node. It relies on hashing to chain blocks and summarise data, and on digital signatures to prove that owners authorised payments. Wallet software may encrypt your private keys on your own device.

What does wallet encryption protect?

In Bitcoin Core, encrypting the wallet protects the private keys with a passphrase, while transactions and other wallet information stay visible. It does not protect against every attack, such as a keylogger. If the passphrase is lost, the coins in the wallet are lost too.

Why do websites hash passwords instead of encrypting them?

Because a site never needs to read your password back, only to check it. NIST's guidance says passwords should be salted with a random value and hashed with a computationally expensive algorithm. If the database is stolen, attackers get hashes they have to guess against, not passwords they can unlock.

Sources

  1. NIST, FIPS 197, Advanced Encryption Standard (AES), updated 9 May 2023
  2. NIST, FIPS 180-4, Secure Hash Standard (August 2015)
  3. NIST, SP 800-63B-4, Passwords
  4. Bitcoin Core documentation, Managing the wallet

Read next.