Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Encryption & Hashing
CN

Encryption & Hashing

Protecting data in transit: Master the difference between Symmetric, Asymmetric encryption and Hashing.

Symmetric Encryption

Same key encrypts and decrypts. Very fast — used for bulk data.

AlgorithmKey sizeStatus
AES128/256 bitsSecure (standard)
DES56 bitsBroken (too small)
ChaCha20256 bitsSecure (modern)

Problem: key distribution. How do two parties who have never met agree on a shared key securely?

Asymmetric Encryption

Two keys: public (shared freely) and private (kept secret). Data encrypted with one can only be decrypted with the other.

AlgorithmKey sizeUse
RSA2048+ bitsKey exchange, signatures
ECDSA256 bitsMore efficient than RSA
Diffie-HellmanVariableKey agreement

Problem: slow (100-1000x slower than symmetric).

Hybrid Encryption (How TLS Works)

  1. Use asymmetric encryption to safely exchange a one-time symmetric key
  2. Use symmetric encryption (AES) for all subsequent data
  3. Best of both worlds: secure key exchange + fast data transfer

Hashing

One-way function. Given input → hash, but hash → input is computationally infeasible.

AlgorithmOutputUse
SHA-256256 bitsGeneral purpose (modern standard)
SHA-1160 bitsDeprecated (collision attacks found)
MD5128 bitsBroken (do not use)

Uses: password storage (hash + salt), data integrity verification, digital signatures.

EncryptionHashing
DirectionTwo-way (reversible)One-way (irreversible)
Output lengthSame as inputFixed length
KeyYesNo
PurposeConfidentialityIntegrity verification

Q: What’s the difference between encryption and hashing?

A: Encryption is two-way — you can encrypt data and decrypt it back to the original. Hashing is one-way — you can create a hash from data but cannot reverse it. Use encryption for confidentiality; use hashing for integrity and password storage.

Q: Why does TLS use both asymmetric and symmetric encryption?

A: Asymmetric encryption solves the key exchange problem (strangers can share a secret securely) but is slow. Symmetric encryption is fast. TLS uses asymmetric to exchange a session key, then symmetric for the actual data.

Q: What is a hash collision?

A: When two different inputs produce the same hash output. For SHA-256, collisions are theoretically possible but computationally infeasible to find. This is why SHA-256 is considered secure but MD5/SHA-1 are not.

Q: What is a salt in password hashing?

A: A random value added to each password before hashing. It ensures that identical passwords produce different hashes, defeating rainbow table attacks.

My Private Notes

Notes are auto-saved locally to this device.