Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Security & hardeningLinux + IT series

Hashing vs Encryption

Hashing and encryption are both called scrambling data, and mixing them up leads to real security mistakes.

Quick reference

HASHINGENCRYPTION
ReversibleNoYes, with the key
Output sizeFixed (256 bits)About the input size
Key neededNoYes
Used forIntegrity, passwordsPrivacy of data
ExamplesSHA-256, bcryptAES, RSA, TLS
PasswordsYes, slow and saltedNever

HASHING (One way, no key): Turns any data into a fixed fingerprint. It cannot be turned back.

sha256sum backup.tar.gz

ENCRYPTION (Two way, with a key): Locks data so only someone with the key can read it again.

gpg -c backup.tar.gz
  • Hashing → prove data has not changed, store passwords.
  • Encryption → keep data secret, and get it back later.

Explained

Hashing is one way. sha256sum backup.tar.gz turns a file of any size into a fixed 256-bit fingerprint. The same input always gives the same hash, and changing a single byte changes it completely. There is no key, and no way to turn the hash back into the original.

Encryption is two way. gpg -c backup.tar.gz locks the file with a key or passphrase. Anyone with the key can decrypt it and get the original data back. Without the key, it is unreadable.

Where each one belongs

Integrity: publish the SHA-256 hash of a download or a backup. Anyone can check the file has not been changed or corrupted. Privacy: encrypt backups before they leave the server, disks with BitLocker or LUKS, and traffic with TLS. The data must be readable again later, so it has to be encryption. Passwords: hash them, never encrypt them. If passwords are encrypted, whoever steals the key gets every password. But use a slow, salted password hash like bcrypt or Argon2, not plain SHA-256, which is fast enough to brute force billions of guesses.

A quick test: do you ever need the original data back? Then you need encryption. Do you only need to check that something matches? Then you need a hash.

Hashing proves. Encryption hides.

More notes: Security & hardening

Open in the notes app: search, filters, copy This note on GitHub