Cybersecurity Fundamentals

Lesson 5 of 7

Cryptography Basics

Cryptography underpins almost every security control: HTTPS, password storage, and secure messaging all depend on it. You don't need to implement algorithms yourself, but you do need to know which tool fits which job.

Hashing vs. encryption

These are often confused, but solve different problems:

HashingEncryption
DirectionOne-way, cannot be reversedTwo-way, can be decrypted with the right key
Use caseVerifying passwords, detecting tamperingProtecting data you need to read again later
Examplebcrypt, SHA-256AES, RSA

Never store passwords in plain text, and never encrypt them either, always hash them with a slow, salted algorithm designed for passwords, like bcrypt:

JavaScript

bcrypt is deliberately slow and includes a random salt per password, so two identical passwords produce different hashes, and brute-forcing many hashes at once can't be sped up with a precomputed table (a "rainbow table").

Symmetric vs. asymmetric encryption

  • Symmetric: the same key encrypts and decrypts (AES). Fast, but both parties need to already share the key securely.
  • Asymmetric: a public key encrypts, only the matching private key can decrypt (RSA). Slower, but solves the key-sharing problem, you can publish your public key freely.

TLS/HTTPS

HTTPS uses both: an asymmetric handshake to securely agree on a shared secret, then fast symmetric encryption for the actual data transfer. This is why the browser padlock icon means the connection is encrypted and the server's identity was verified by a certificate, but it says nothing about whether the site itself is trustworthy.

TIP

"Encrypted" is not the same as "secure": a phishing site can have a valid HTTPS certificate too. TLS protects data in transit, it doesn't vouch for who's on the other end.

📝 Cryptography Quiz

Passing score: 70%
  1. 1.Which is the correct way to store user passwords?

  2. 2.A valid HTTPS certificate guarantees that a website itself is trustworthy, not just that the connection is encrypted.

  3. 3.In ____ encryption, the same key is used to both encrypt and decrypt the data.