Secret Key Algorithm (Symmetric Encryption Algorithm) คืออะไร?
Secret Key Algorithm หรือ Symmetric Encryption Algorithm คือ อัลกอริทึมเข้ารหัสที่ใช้ คีย์เดียวกัน (Single Key / Secret Key / Private Key) สำหรับทั้ง การเข้ารหัส (Encryption) และ การถอดรหัส (Decryption) คีย์นี้ต้องเก็บความลับและแบ่งปันระหว่างฝ่ายสื่อสารอย่างปลอดภัย
🔐 หลักการทำงาน
Plaintext + Secret Key + Algorithm → Ciphertext
Ciphertext + Secret Key + Algorithm → Plaintext
- ความเร็วสูง (เหมาะกับข้อมูลขนาดใหญ่ / Bulk Encryption)
- ต้องมีวิธีแลกเปลี่ยนคีย์อย่างปลอดภัย (Key Exchange Problem) → ใช้ Asymmetric Crypto (Diffie-Hellman, RSA) หรือ Key Distribution Center (KDC/Kerberos)
- ใช้ร่วมกับ Mode of Operation (CBC, GCM, CTR, CCM) และ Padding (PKCS#7)
📋 อัลกอริทึมสำคัญ (Standard Algorithms)
| อัลกอริทึม | Key Size | Block Size | สถานะ/การใช้งาน |
| AES (Advanced Encryption Standard) 🏆 | 128, 192, 256 bits | 128 bits | มาตรฐานโลก (FIPS 197) ใช้ทุกที่: TLS, IPsec, Wi-Fi (WPA2/3), Disk Encryption (BitLocker, FileVault), SSH, ZIP |
| ChaCha20-Poly1305 🏆 | 256 bits | Stream (512 bits) | เร็วกว่า AES บน CPU ไม่มี AES-NI ใช้ใน TLS 1.3, WireGuard, SSH, QUIC |
| 3DES (Triple DES) | 168 bits (Effective 112) | 64 bits | ❌ Deprecated (NIST SP 800-131A) ช้า, Sweet32 Attack ยกเลิก TLS 1.2/1.3 |
| RC4 | 40-2048 bits | Stream | ❌ ห้ามใช้ Bias Attacks, ทิ้งทิ้งแล้ว |
| Blowfish / Twofish | 32-448 / 128-256 bits | 64 / 128 bits | Legacy / ไม่ใช่มาตรฐาน Twofish รองใน AES Contest |
| Camellia | 128, 192, 256 bits | 128 bits | มาตรฐานญี่ปุ่น/สากล (ISO/IEC 18033-3) ใช้ใน TLS, IPsec, NESSIE |
| SM4 | 128 bits | 128 bits | มาตรฐานจีน (GB/T 32907) ใช้ใน China National Standards |
🔧 Modes of Operation (สำคัญมาก!)
| Mode | ลักษณะ | IV/Nonce | Parallel | Integrity | ใช้งาน |
| ECB | แต่ละ Block แยกกัน | ไม่ต้องการ | ✅ | ❌ | ❌ ห้ามใช้ (Pattern Leak) |
| CBC | Chain ต่อกัน | IV (Random) | ❌ Enc / ✅ Dec | ❌ | Legacy (TLS 1.2, File Enc) ต้องมี Padding |
| CTR | Counter Mode (Stream-like) | Nonce + Counter | ✅ | ❌ | Disk Enc, IPsec, TLS 1.2 (with HMAC) |
| GCM (Galois/Counter Mode) 🏆 | AEAD (Auth + Enc) | Nonce (96-bit) | ✅ | ✅ Built-in | มาตรฐานปัจจุบัน TLS 1.3, SSH, IPsec, WPA3, QUIC |
| CCM | AEAD (CBC-MAC + CTR) | Nonce | ❌ | ✅ | Wi-Fi (WPA2 CCMP), Zigbee, BLE |
| OCB | AEAD (Efficient) | Nonce | ✅ | ✅ | Patented (Exp 2020) ใช้ได้น้อย |
🔑 การจัดการคีย์ (Key Management) - จุดอ่อนหลัก
- Key Generation: CSPRNG (Cryptographically Secure PRNG) /dev/urandom, BCryptGenRandom, getrandom()
- Key Exchange: Diffie-Hellman (ECDHE, FFDHE), RSA Key Transport, KEM (Kyber - PQC), Kerberos, PAKE (OPAQUE, SPAKE2)
- Key Derivation: HKDF, PBKDF2, Argon2, scrypt (จาก Password/Master Key)
- Key Storage: HSM (Hardware Security Module), TPM, Secure Enclave, KMS (AWS KMS, Azure Key Vault, HashiCorp Vault), Key Vaults
- Key Rotation: เปลี่ยนคีย์เป็นระยะ (NIST: 1-2 ปีสำหรับ Symmetric Keys) Automated
- Key Destruction: Secure Erase (Crypto-shredding) เมื่อหมดอายุ
🛡️ การใช้งานจริง (Real-world Usage)
- TLS 1.3: AES-GCM / ChaCha20-Poly1305 (AEAD) กับ Session Keys จาก ECDHE
- IPsec ESP: AES-GCM / AES-CBC+HMAC / ChaCha20-Poly1305
- Wi-Fi (WPA2/WPA3): AES-CCMP (WPA2), AES-GCMP (WPA3) + SAE
- Disk Encryption: BitLocker (AES-XTS), FileVault (AES-XTS), LUKS (AES-XTS/GCM)
- Database/Application Encryption: AES-GCM (AEAD) สำหรับ Field-level Encryption
- Messaging (Signal, WhatsApp): Double Ratchet (Chain of Symmetric Keys from DH)
⚡ Symmetric vs Asymmetric
| คุณสมบัติ | Symmetric (Secret Key) | Asymmetric (Public Key) |
| Speed | ⚡ เร็วมาก (1000-10000x) | 🐢 ช้า |
| Key Distribution | 😫 ยาก (Key Exchange Problem) | 😊 ง่าย (Public Key แจกได้) |
| Scalability (N parties) | O(N²) Keys | O(N) Key Pairs |
| Non-repudiation | ❌ ไม่ได้ (Shared Secret) | ✅ ได้ (Digital Signature) |
| Typical Use | Bulk Data Encryption | Key Exchange, Digital Signatures, Certificates |
🔮 อนาคต: Post-Quantum Cryptography (PQC)
- NIST PQC Standards (2024): ML-KEM (Kyber - KEM), ML-DSA (Dilithium - Signature), SLH-DSA (SPHINCS+ - Signature)
- Symmetric: AES-256, ChaCha20 ยังปลอดภัย (Grover's Algorithm ลดความแข็งแกร่งเหลือครึ่ง Key Size → ใช้ 256-bit)
- Hybrid Approaches: Classical + PQC (X25519+Kyber, ECDSA+Dilithium) ใน TLS 1.3, SSH, Signal
💡 สรุป
Secret Key Algorithm = Symmetric Encryption = ใช้คีย์เดียวกันเข้ารหัส/ถอดรหัส AES-GCM และ ChaCha20-Poly1305 เป็นมาตรฐานทองคำปัจจุบัน (AEAD: Authenticated Encryption with Associated Data) จุดสำคัญ: Key Management (Generation, Exchange, Storage, Rotation, Destruction) และการเลือก Mode ที่ถูกต้อง (อย่าใช้ ECB, ควรใช้ GCM/CCM)