Core Module
12 min forge

Encryption

Master the logic of data secrecy. Learn the difference between Symmetric and Asymmetric encryption, Hashing, and Salting.

πŸ” Encryption: Keeping Data Private

Encryption is the process of converting information or data into a code, especially to prevent unauthorized access.

πŸ’‘ The Logic (ELI5)

Symmetric Encryption (Single Key)

Think of a Locked Diary:

  • You have one key.
  • You lock the diary with the key.
  • To read it, you must use the same key to unlock it.
  • It's fast, but if you want your friend to read it, you have to mail them the physical key (The secret sharing problem).

Asymmetric Encryption (Two Keys)

Think of a Mailbox:

  • The Public Key: This is the slot in the door. Anyone can put mail into the box.
  • The Private Key: This is the key that opens the back of the box. Only you have this key.
  • People can send you secrets, but even the person who sent it can't take it back out once it's in.

πŸ” The Deep Dive

Symmetric Encryption

  • Key: Same key for encrypting and decrypting.
  • Pros: Very fast (often hardware-accelerated).
  • Cons: Hard to share the key securely across the internet.
  • Example: AES (Advanced Encryption Standard).

Asymmetric Encryption

  • Key: A "Public Key" for encryption and a "Private Key" for decryption.
  • Pros: Perfectly solves the key sharing problem.
  • Cons: 100x to 1000x slower than symmetric encryption.
  • Example: RSA, Elliptic Curve (ECC).

Hashing vs Encryption

  • Encryption: Two-way. You can turn the code back into the original message.
  • Hashing: One-way. You can turn "Password123" into "a8sd7f..." but you can NEVER turn "a8sd7f..." back into "Password123." (Used for password storage).

🎯 Interview Pulse

Use Case: Hybrid Encryption

How does HTTPS stay fast if Asymmetric encryption is slow? Answer: It uses Hybrid Encryption. It uses Asymmetric encryption just once at the start to "exchange" a secret Symmetric key. Then, for the rest of the session, it uses Symmetric encryption (AES) because it's fast.

Key Terms to Mention

  • Salting: Adding random noise to hashes so two people with the same password have different hashes.
  • Encryption at Rest: Encrypting the Database files on the physical hard drive.
  • Encryption in Transit: Encrypting data as it travels over the network (TLS/HTTPS). πŸ›‘οΈ