SECURITY / A CONCEPT NOTE

Hashing vs Encryption

one-way vs two-way

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Hashing is a one-way mathematical function that outputs a fixed-length string (like SHA256) and cannot be reversed. Encryption is a two-way function that can be reversed using a secret key.

02 / FOLLOW THE MECHANISM

How hashing vs encryption flows

  1. Hash check

    system hashes user password at login and compares the result to the stored database hash.

  2. Encryption run

    encrypts database data (ciphertext) before writing to disk.

  3. Decryption run

    reads ciphertext from disk, applying key to decrypt it back to plaintext.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

generate a SHA256 hash of a string

echo -n "password" | sha256sum

EXAMPLE 02 · REFERENCE

encrypt a file symmetrically with a passphrase

gpg -c secrets.txt

Explore command anatomy in the CLI lab