Cryptography (ทฤษฎีการเข้ารหัส) คืออะไร?
Cryptography คือวิทยาศาสตร์และศิลปะของการปกป้องข้อมูลโดยการแปลงข้อมูลเดิม (Plaintext) ให้กลายเป็นข้อมูลที่อ่านไม่ออก (Ciphertext) เพื่อให้เฉพาะฝ่ายที่ได้รับอนุญาต (มี Key) เท่านั้นที่สามารถกลับมาอ่านได้ (Decryption) เป้าหมายหลัก: Confidentiality, Integrity, Authentication, Non-repudiation
ความสัมพันธ์: Cryptography vs Network Security vs Cybersecurity
| Domain | Focus | Relationship |
|---|---|---|
| Cryptography | Mathematical Techniques: Encryption, Hashing, Signatures, Key Exchange | Foundation / Building Block |
| Network Security | Protect Data in Transit (Network Layer): TLS, IPsec, VPN, SSH, DNSSEC | Applies Crypto to Network Protocols |
| Cybersecurity | Protect All Digital Assets: Network, Endpoint, App, Cloud, Data, Identity | Umbrella Term (Includes Network Security) |
3 ประเภทหลักของ Cryptography
1. Symmetric Key Cryptography (Private/Secret Key)
- ใช้ Key เดียวกัน สำหรับ Encrypt และ Decrypt
- เร็ว, เหมาะสำหรับข้อมูลปริมาณมาก (Bulk Encryption)
- ปัญหา: Key Distribution (อย่างไรส่ง Key ให้ปลายทางปลอดภัย?)
- Algorithms: AES (Standard), ChaCha20, DES/3DES (Deprecated), Blowfish/Twofish
- Modes: ECB (Weak), CBC, CTR, GCM (Authenticated Encryption - แนะนำ)
2. Asymmetric Key Cryptography (Public Key Cryptography)
- ใช้ Key Pair: Public Key (แจกจ่ายได้) + Private Key (เก็บความลับ)
- Public Key: Encrypt / Verify Signature
- Private Key: Decrypt / Create Signature
- ช้ากว่า Symmetric → ใช้สำหรับ Key Exchange, Digital Signature, Small Data
- Algorithms: RSA (2048/4096-bit), ECC (ECDSA, EdDSA - Curve25519, P-256), Diffie-Hellman, ElGamal
- Hybrid Cryptosystem: Asymmetric สำหรับ Key Exchange + Symmetric สำหรับ Data (TLS, PGP, SSH)
3. Hash Functions / Cryptographic Hashing
- One-way Function: Input (Arbitrary Length) → Fixed-length Output (Hash/Digest)
- Properties: Deterministic, Fast, Pre-image Resistance, Collision Resistance, Avalanche Effect
- ไม่ใช่ Encryption (ไม่มี Key, ไม่สามารถ Decrypt ได้)
- Algorithms: SHA-256, SHA-384, SHA-512, SHA-3 (Keccak), BLAKE2/3
- Deprecated: MD5, SHA-1 (Collision Found)
- Uses: Integrity Check, Digital Signatures, Password Hashing (with Salt + Slow Hash: Argon2, bcrypt, PBKDF2, scrypt), Blockchain, Certificates
Key Cryptographic Protocols ใน Network Security
| Protocol | Purpose | Crypto Used |
|---|---|---|
| TLS 1.2/1.3 (HTTPS) | Secure Web, API | ECDHE (Key Exch), AES-GCM/ChaCha20-Poly1305 (AEAD), RSA/ECDSA/EdDSA (Auth) |
| IPsec (ESP/AH) | VPN, Site-to-Site | IKEv2 (DH/ECDH), AES-GCM, SHA-256/384 |
| SSH | Remote Access, SFTP | ECDH, Ed25519, ChaCha20-Poly1305, AES-GCM |
| WireGuard | Modern VPN | Curve25519 (DH), ChaCha20-Poly1305, BLAKE2s, HKDF |
| DNSSEC | DNS Integrity/Auth | RSA/ECDSA, SHA-256, NSEC/NSEC3 |
| S/MIME, PGP/GPG | Email Encryption/Sign | RSA/ECC, AES, SHA |
| Kerberos | Auth (Windows AD) | AES, RC4 (Deprecated), SPNEGO |
| 802.1X (EAP-TLS/PEAP) | Network Access Control | TLS (Cert-based), MS-CHAPv2 |
หลักการพื้นฐานของ Cryptography & Network Security (CIA + Auth + Non-rep)
- Confidentiality: Encryption (Symmetric/Asymmetric/Hybrid)
- Integrity: Hash (HMAC), Authenticated Encryption (AES-GCM, ChaCha20-Poly1305), Digital Signature
- Availability: ไม่ใช่ Crypto โดยตรง แต่ Redundancy, DDoS Protection, Backup
- Authentication: Digital Signature, Certificates (PKI), MAC, Password/Token/Biometric
- Non-repudiation: Digital Signature (Private Key Sign → Public Key Verify), Audit Logs
- Access Control: ACL, RBAC, ABAC, Zero Trust (Policy Enforcement Points)
Modern Encryption Standards (2024)
- Symmetric: AES-256-GCM, ChaCha20-Poly1305 (Preferred for Mobile/Non-AES-NI)
- Asymmetric: ECC (Curve25519/Ed25519, P-256/ECDSA) > RSA-3072/4096 (Performance + Key Size)
- Hash: SHA-256/384/512, SHA-3, BLAKE3
- KDF: HKDF, Argon2id (Password), PBKDF2 (Legacy)
- Post-Quantum (PQC): CRYSTALS-Kyber (KEM), CRYSTALS-Dilithium (Sig), SPHINCS+ (Sig) - NIST Standardized 2024
Cryptographic Attacks
- Brute Force: ลอง Key ทุกค่า (Key Space ใหญ่ = ป้องกันได้)
- Side-channel: Timing, Power, EM, Cache (Spectre/Meltdown)
- Cryptanalysis: Mathematical Weakness (Differential, Linear, Algebraic)
- Implementation Flaws: RNG Weakness, Padding Oracle (POODLE, Lucky13), Nonce Reuse (GCM)
- Protocol Attacks: Downgrade (POODLE, FREAK, Logjam), Reflection, Replay
- Quantum (Future): Shor's Algorithm (Breaks RSA/ECC), Grover's (Weakens Symmetric 2x)
Key Management (Critical!)
- Generation: CSPRNG (OS: /dev/urandom, getrandom(), BCryptGenRandom, CryptGenRandom)
- Storage: HSM (Hardware Security Module), TPM, Secure Enclave, KMS (AWS KMS, Azure Key Vault, HashiCorp Vault)
- Distribution: PKI (Certificates), Key Exchange (DH/ECDH), Out-of-band
- Rotation: Periodic, On-compromise, Crypto-periods
- Revocation: CRL, OCSP, Certificate Transparency, Short-lived Certs
- Destruction: Secure Erase, Zeroize
3 Basic Operations in Cryptography
- Encryption: Plaintext + Key → Ciphertext
- Decryption: Ciphertext + Key → Plaintext
- Hashing: Input → Fixed-length Digest (One-way, No Key)
สรุป
Cryptography เป็น "โครงร่าง" (Foundation) ของ Network Security ให้ Confidentiality, Integrity, Authenticity, Non-repudiation ผ่าน Symmetric (AES-GCM), Asymmetric (ECC/RSA), Hash (SHA-2/3), และ Protocols (TLS 1.3, IPsec, WireGuard, SSH) จุดสำคัญที่สุด: Key Management และ Correct Implementation (Don't Roll Your Own Crypto) รอ Post-Quantum Cryptography (PQC) Migration ในอีก 5-10 ปี