Skip to content
BENIBIX Learn

Hashing (Cryptography)

Development🔐 SecurityDefences

Also known as Hash, Hash Function, Cryptographic Hash, SHA-256, Checksum

Turning any data into a short code. It can never be turned back.

Think of it like

Think of it like a fingerprint for a file. A tiny change makes a whole new print.

Example

Jack downloads a 2 GB file and its published SHA-256 hash. He hashes his copy, the two match, so the file arrived unchanged.

Why it matters

It lets you prove data was not changed, and store secrets you never need to read back.

Definition

Hashing turns any data into a short code of fixed length, called a hash. It cannot be undone. The same input always gives the same hash. Change one letter and the hash changes completely. SHA-256 is a common method, and its hash is 64 characters of hex. Hashes are used to check files were not changed and, with slow methods, to store passwords.

Example code

console
$ echo -n hello | sha256sum
2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824  -
$ echo -n Hello | sha256sum
185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969  -
One capital letter, and the whole hash changes.

Common mistake

Calling hashing a kind of encryption. Encryption can be undone with a key; a hash cannot be undone at all.

Key takeaways

  1. 1
    One way. No way back.
  2. 2
    Same in, same out. Every time.
  3. 3
    Small change, new hash. Changes are easy to spot.

Compare