Symmetric Encryption คืออะไร?
Symmetric Encryption (การเข้ารหัสแบบสมมาตร) เป็นวิธีเข้ารหัสที่ใช้ คีย์เดียว (Secret Key) ทั้งในการเข้ารหัส (Encryption) และถอดรหัส (Decryption) ทั้งผู้ส่งและผู้รับต้องมีคีย์เดียวกันนี้ล่วงหน้า
ลักษณะสำคัญ
- Speed: เร็วมาก (ประมาณ 1000-10000x Asymmetric) เหมาะเข้ารหัสข้อมูลปริมาณมาก
- Key Size: สั้นกว่า Asymmetric (เช่น AES-256 ใช้ 256-bit vs RSA 3072-bit)
- Key Distribution Problem: จุดอ่อนหลัก - ต้องส่งคีย์ลับให้ผู้รับอย่างปลอดภัย (Out-of-band หรือผ่าน Asymmetric Key Exchange)
- ไม่ให้ Non-repudiation: ใครมีคีย์ก็สามารถเข้ารหัส/ถอดรหัสได้ ไม่พิสูจน์ตัวตนผู้ส่งได้
อัลกอริทึม Symmetric ยอดนิยม
| อัลกอริทึม | ประเภท | Key Size | สถานะ/การใช้งาน |
|---|---|---|---|
| AES (Advanced Encryption Standard) | Block Cipher | 128, 192, 256-bit | มาตรฐานโลก (FIPS 197) ใช้ใน TLS, IPsec, BitLocker, FileVault, Signal |
| ChaCha20 | Stream Cipher | 256-bit | ทันสมัย เร็วบน CPU ไม่มี AES-NI ใช้ใน TLS 1.3, WireGuard, SSH |
| 3DES (Triple DES) | Block Cipher | 168-bit (eff. 112) | ล้าสมัย ช้า มีช่องโหว่ Sweet32 ห้ามใช้ใหม่ |
| Blowfish / Twofish | Block Cipher | ตัวแปร | เก่า กำลังถูกแทนที่ด้วย AES/ChaCha20 |
| RC4 | Stream Cipher | 40-2048-bit | แตกแล้ว ห้ามใช้ |
โหมดการทำงานของ Block Cipher (Modes of Operation)
| โหมด | คุณสมบัติ | ใช้งาน |
|---|---|---|
| ECB | ไม่ควรใช้ (รูปแบบข้อมูลซ้ำเห็นได้) | ห้ามใช้ |
| CBC | ต้องมี IV, Sequential, Padding Oracle attacks | TLS 1.2 (Legacy) |
| GCM (Galois/Counter Mode) | AEAD: Encrypt + Auth ในขั้นเดียว, Parallel, เร็ว | TLS 1.3, IPsec, SSH, 標準推薦 |
| CTR | Stream-like, Parallel, ต้องแยก MAC | Special cases |
Symmetric vs Asymmetric Encryption
| ด้านเปรียบเทียบ | Symmetric | Asymmetric (Public Key) |
|---|---|---|
| จำนวนคีย์ | 1 คีย์ (Secret Key) | คู่คีย์: Public + Private |
| ความเร็ว | เร็วมาก | ช้า (คณิตศาสตร์ซับซ้อน) |
| ขนาดคีย์ | สั้น (128-256-bit) | ยาว (2048-4096-bit RSA, 256-bit ECC) |
| Key Exchange | ยาก (ต้องมีช่องทางปลอดภัย) | ง่าย (Public Key ส่งสาธารณะได้) |
| Non-repudiation | ไม่มี | มี (Digital Signature) |
| Use Case หลัก | เข้ารหัสข้อมูลปริมาณมาก (Data at rest, Data in transit) | Key Exchange, Digital Signature, PKI, TLS Handshake |
Hybrid Encryption: รวมข้อดีทั้งสอง
ระบบจริงใช้ Hybrid Approach:
- ใช้ Asymmetric (เช่น ECDH, RSA-KEM) เพื่อ Key Exchange สร้าง Shared Secret
- นำ Shared Secret มา derive เป็น Symmetric Key (AES-GCM, ChaCha20-Poly1305)
- ใช้ Symmetric Key เข้ารหัสข้อมูลจริง (Bulk Encryption)
ตัวอย่าง: TLS 1.3, Signal Protocol, SSH, IPsec IKEv2, PGP/GPG
HTTPS ใช้ Symmetric หรือ Asymmetric?
ทั้งคู่ Handshake ใช้ Asymmetric (ECDHE/RSA) เพื่อแลกเปลี่ยนคีย์ แล้ว Session ใช้ Symmetric (AES-GCM/ChaCha20-Poly1305) เข้ารหัส HTTP Traffic
Best Practices 2024
- ใช้ AES-256-GCM หรือ ChaCha20-Poly1305 (AEAD modes)
- ไม่ใช้ ECB, CBC (โดยไม่มี MAC), 3DES, RC4, Blowfish
- Key Management: ใช้ HSM/KMS (AWS KMS, Azure Key Vault, HashiCorp Vault)
- Key Rotation: หมุนเวียนคีย์เป็นระยะ (90-365 วัน)
- ใช้ Library มาตรฐาน: libsodium, OpenSSL, Bouncy Castle, Go crypto, Python cryptography อย่าเขียน Crypto เอง