This is an old revision of the document!
Table of Contents
Cryptography Fundamentals
This document introduces the fundamental concepts of cryptography.
—
Why Do We Need Cryptography?
When systems communicate over a network, there are three main security goals:
* Confidentiality * Integrity * Authenticity
Cryptography helps achieve these goals.
—
Security Goals
Confidentiality
Only authorized parties can read the data.
Example:
Alice sends a password to Bob. Alice ---- Internet ---- Bob ^ Attacker
Without protection, the attacker can read the password.
Solution:
Encryption
—
Integrity
Data must not be modified during transmission.
Example:
Original: Transfer $100 Modified: Transfer $10000
Solution:
Digital Signatures
—
Authenticity
Verify who actually sent the data.
Example:
Someone claims to be your bank.
How do you know it is really your bank?
Solution:
Digital Signatures Certificates
—
What Is Cryptography?
Cryptography is the practice of protecting information.
Main categories:
Cryptography │ ├── Encryption │ └── Digital Signatures
—
What Is A Key?
A key is a secret value used by cryptographic algorithms.
Think of it like a house key:
With key -> Open the door Without key -> Cannot open the door
—
Encryption
Encryption protects:
Confidentiality
Goal:
Prevent unauthorized parties from reading data.
Process:
Plain Text
↓
Encrypt
↓
Cipher Text
↓
Decrypt
↓
Plain Text
Example:
Hello World
↓
A83D91F22C...
Only someone with the correct key can recover the original message.
—
Types of Encryption
Encryption can be implemented using:
* Symmetric Cryptography * Asymmetric Cryptography
—
Symmetric Cryptography
Uses:
ONE SECRET KEY
for both encryption and decryption.
Workflow:
Secret Key
↓
Encrypt
↓
Cipher Text
↓
Decrypt
↓
Plain Text
Example:
Encrypt("Hello", secret_key)
Decrypt(ciphertext, secret_key)
Advantages:
* Fast * Efficient * Easy to implement
Disadvantages:
* Secret key must be shared securely * If the key leaks, all data can be decrypted
Common algorithms:
* AES * ChaCha20 * DES (legacy)
—
Asymmetric Cryptography
Uses:
TWO KEYS Public Key Private Key
The keys are mathematically related.
Public Key:
* Can be shared publicly
Private Key:
* Must remain secret
—
Asymmetric Encryption
Purpose:
Confidentiality
Workflow:
Public Key -> Encrypt Private Key -> Decrypt
Example:
Alice owns:
Public Key Private Key
Bob wants to send a secret message:
Encrypt(message, Alice Public Key)
Alice decrypts:
Decrypt(ciphertext, Alice Private Key)
Result:
Anyone can encrypt. Only Alice can decrypt.
—
Digital Signatures
Digital signatures provide:
* Integrity * Authenticity
Workflow:
Private Key -> Sign Public Key -> Verify
Example:
Document
↓
Sign with Private Key
↓
Signed Document
Verification:
Signed Document
↓
Verify with Public Key
↓
Valid / Invalid
Result:
Only the owner can sign. Everyone can verify.
—
Encryption vs Digital Signature
Encryption
Goal:
Hide data
Question answered:
Can someone read this?
Can use:
Symmetric Cryptography Asymmetric Cryptography
Workflow:
Public Key -> Encrypt Private Key -> Decrypt
or
Secret Key -> Encrypt Secret Key -> Decrypt
—
Digital Signature
Goal:
Verify authenticity Detect tampering
Questions answered:
Who sent this? Was this modified?
Uses:
Asymmetric Cryptography
Workflow:
Private Key -> Sign Public Key -> Verify
—
Real-World Examples
| Technology | Encryption | Digital Signature |
|---|---|---|
| HTTPS/TLS | AES, ChaCha20 | RSA, ECDSA, Ed25519 |
| SSH | AES, ChaCha20 | RSA, Ed25519 |
| JWT HS256 | HMAC (shared secret) | No |
| JWT RS256 | No | RSA Signature |
| JWT ES256 | No | ECDSA Signature |
| PGP/GPG | Yes | Yes |
—
Easy Way To Remember
Encryption = Hide data = Confidentiality # Digital Signature Verify sender + Detect tampering ================ Authenticity + Integrity # Symmetric 1 Secret Key # Asymmetric Public Key + Private Key # Encryption Symmetric OR Asymmetric # Digital Signature Asymmetric
