Module 77: Encryption and Secrets

Lesson 2 of 5 · 15–25 minutes

Hashing vs encryption

🏠The everyday picture

Encryption is a locked box: with the key, you get the contents back. Hashing is a fingerprint: it identifies the person, but you can't rebuild the person from it.

📘What it really is

🖱️Try it

In Node.js, hash "hello" and "hello!" with SHA-256 (crypto.createHash("sha256").update(s).digest("hex")) and compare. Hash the same password twice with bcrypt and notice the results differ (the salt), yet both verify. Time 10 bcrypt hashes at cost 12 against 10 SHA-256 hashes, and explain why the slow one is right for passwords.

✅Quick check

Why should passwords be hashed rather than encrypted?

Show the answer

You only ever need to check them, never read them back; hashing means even a stolen database doesn't reveal them.

Why are fast hashes like SHA-256 wrong for passwords?

Show the answer

Attackers can try billions of guesses per second; password hashes are deliberately slow and salted.

← PreviousEncryption in transit and at rest
ProLearners Assist