Symmetric Encryption
Same key encrypts and decrypts. Very fast — used for bulk data.
| Algorithm | Key size | Status |
|---|---|---|
| AES | 128/256 bits | Secure (standard) |
| DES | 56 bits | Broken (too small) |
| ChaCha20 | 256 bits | Secure (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.
| Algorithm | Key size | Use |
|---|---|---|
| RSA | 2048+ bits | Key exchange, signatures |
| ECDSA | 256 bits | More efficient than RSA |
| Diffie-Hellman | Variable | Key agreement |
Problem: slow (100-1000x slower than symmetric).
Hybrid Encryption (How TLS Works)
- Use asymmetric encryption to safely exchange a one-time symmetric key
- Use symmetric encryption (AES) for all subsequent data
- Best of both worlds: secure key exchange + fast data transfer
Hashing
One-way function. Given input → hash, but hash → input is computationally infeasible.
| Algorithm | Output | Use |
|---|---|---|
| SHA-256 | 256 bits | General purpose (modern standard) |
| SHA-1 | 160 bits | Deprecated (collision attacks found) |
| MD5 | 128 bits | Broken (do not use) |
Uses: password storage (hash + salt), data integrity verification, digital signatures.
| Encryption | Hashing | |
|---|---|---|
| Direction | Two-way (reversible) | One-way (irreversible) |
| Output length | Same as input | Fixed length |
| Key | Yes | No |
| Purpose | Confidentiality | Integrity 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.
Premium Content
Unlock Encryption & Hashing and all premium lessons with a subscription.
From ₹199.99/year — See plans