Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

K ในการเข้ารหัส Network Security (Encryption Key: DEK, KEK, KMS) คืออะไร?

K (Key) ใน Network Security Encryption คืออะไร?

ในทฤษฎีการเข้ารหัส (Cryptography) และระบบจัดการคีย์ (Key Management) "K" มักใช้แทน Key (คีย์/กุญแจ) ซึ่งมีหลายประเภทและบทบาทที่แตกต่างกันไป

ประเภทคีย์หลักในระบบเข้ารหัสสมัยใหม่

1. Data Encryption Key (DEK) - คีย์เข้ารหัสข้อมูล

  • หน้าที่: ใช้เข้ารหัส/ถอดรหัส ข้อมูลจริง (Data/Plaintext) ให้กลายเป็น Ciphertext และกลับมา
  • ลักษณะ: เป็น Symmetric Key (คีย์เดียวกัน ใช้เข้ารหัสและถอดรหัส) มักเป็น AES-256, AES-128, ChaCha20-Poly1305
  • อายุการใช้งาน: สั้น (Ephemeral) สร้างใหม่ต่อ Session/File/Message (Key Rotation)
  • ตัวอย่าง: TLS Session Key, File Encryption Key, Disk Encryption Key, Database Column Key

2. Key Encryption Key (KEK) - คีย์เข้ารหัสคีย์ (Key Wrapping Key)

  • หน้าที่: ใช้เข้ารหัส/ถอดรหัส DEK (Key Wrapping / Key Encapsulation) เพื่อเก็บ/ส่ง DEK อย่างปลอดภัย
  • ลักษณะ: สามารถเป็น Symmetric (AES-KW, AES-GCM) หรือ Asymmetric (RSA-OAEP, ECIES)
  • อายุการใช้งาน: ยาว (Long-lived) จัดการโดย KMS/HSM
  • ลำดับชั้น (Key Hierarchy): Master Key (Root) > KEK(s) > DEK(s) > Data

3. Master Key / Root Key / Key Master Key (KMK)

  • คีย์ราก (Root of Trust) ใช้สร้าง/ปกป้อง KEK มักเก็บใน HSM (Hardware Security Module) หรือ Cloud KMS (AWS KMS, Azure Key Vault, GCP Cloud KMS, HashiCorp Vault)
  • ไม่เคยออกจาก HSM/KMS (Non-exportable)

4. Public Key / Private Key (Asymmetric Key Pair)

  • Public Key (K_pub): แจกจ่ายสาธารณะ ใช้เข้ารหัส (Encrypt) หรือ Verify Signature
  • Private Key (K_priv): เก็บความลับ ใช้ถอดรหัส (Decrypt) หรือ Sign
  • ใช้ใน: TLS (Server Cert), SSH, PGP/GPG, S/MIME, Code Signing, FIDO2/WebAuthn, Blockchain

Key Hierarchy (ลำดับชั้นคีย์) ตัวอย่างมาตรฐาน

Root CA / Master Key (HSM/KMS)  [Non-exportable, Long-term]
       │
       ▼ (Key Derivation / Wrapping)
Key Encryption Key (KEK)        [Long-term, Rotated periodically]
       │
       ▼ (Key Wrapping / Envelope Encryption)
Data Encryption Key (DEK)       [Short-term, Per Session/File/Record]
       │
       ▼ (Encryption)
Plaintext Data  ──►  Ciphertext

Envelope Encryption (การเข้ารหัสแบบซ้อนซ้อน) - มาตรฐานอุตสาหกรรม

  1. สร้าง DEK แบบสุ่ม (Random) สำหรับข้อมูลชิ้นนั้น
  2. เข้ารหัสข้อมูลด้วย DEK (AES-GCM / ChaCha20-Poly1305)
  3. เข้ารหัส DEK ด้วย KEK (AES Key Wrap / RSA-OAEP / KMS Encrypt API)
  4. เก็บ Encrypted DEK + Ciphertext + Metadata (Key ID, IV, Tag) รวมกัน
  5. ถอดรหัส: เรียก KMS/HSM ถอดรหัส Encrypted DEK ด้วย KEK > ได้ DEK > ถอดรหัสข้อมูล

ข้อดี: DEK หมุนเวียนบ่อย (Key Rotation) ไม่ต้อง Re-encrypt ข้อมูลทั้งหมด แค่ Re-wrap DEK ใหม่ด้วย KEK ใหม่

Key Management System (KMS) และ Hardware Security Module (HSM)

  • KMS (Key Management System): บริการจัดการวงจรชีวิตคีย์ (Generate, Store, Rotate, Revoke, Destroy, Access Control, Audit Logging) - Cloud: AWS KMS, Azure Key Vault, GCP Cloud KMS, HashiCorp Vault, Thales CipherTrust
  • HSM (Hardware Security Module): อุปกรณ์ฮาร์ดแวร์เฉพาะทาง (FIPS 140-2/3 Level 2/3/4) สำหรับ Generate, Store, Use Keys ในสภาพแวดล้อม Tamper-resistant (Thales Luna, nCipher/nShield, Utimaco, AWS CloudHSM, Azure Dedicated HSM, Google Cloud HSM)

3 ประเภทการเข้ารหัสหลัก (Three Main Encryption Types)

  1. Symmetric Encryption (Secret Key): คีย์เดียว ใช้เข้ารหัส/ถอดรหัส (AES, ChaCha20, DES/3DES - ล้าสมัย) - เร็ว ใช้เข้ารหัสข้อมูลขนาดใหญ่ (DEK)
  2. Asymmetric Encryption (Public Key): คีย์คู่ Public/Private (RSA, ECC/ECDSA, EdDSA, ElGamal) - ช้ากว่า ใช้ Key Exchange, Digital Signature, Encrypt KEK/DEK (Small Data)
  3. Hybrid Encryption: รวมทั้งสอง: Asymmetric เพื่อแลกเปลี่ยน/ปกป้อง Symmetric Key (DEK/Session Key) แล้ว Symmetric ใช้เข้ารหัสข้อมูลจริง (TLS, SSH, PGP, Signal Protocol, Age, SSH)

คีย์อื่นๆ ที่เกี่ยวข้อง

  • Session Key / Traffic Key: DEK สำหรับ Session เดียว (TLS, SSH, IPsec, WireGuard)
  • Pre-Shared Key (PSK): Symmetric Key ที่แชร์ไว้ล่วงหน้า (Wi-Fi WPA2-PSK, WireGuard, IPsec PSK)
  • Master Secret (TLS): Derived จาก Key Exchange (ECDHE) ใช้สร้าง Session Keys
  • Key Derivation Function (KDF): HKDF, PBKDF2, Argon2, Scrypt, Balloon - สร้างคีย์จาก Password/Secret/Key Material
  • Initialization Vector (IV) / Nonce: ไม่ใช่ Key แต่จำเป็นสำหรับ Encryption Mode (GCM, CBC, CTR) ต้อง Unique Per Key
  • Salt: Random Data ใช้กับ KDF (Password Hashing) ป้องกัน Rainbow Table

DES (Data Encryption Standard) - บทเรียนจากอดีต

  • พัฒนาโดย IBM/NSA (1975) มาตรฐานสหรัฐ (FIPS 46) 56-bit Key, 64-bit Block, Feistel Network
  • แตกได้แล้ว (1997-1999) ด้วย Brute Force (EFF Deep Crack, distributed.net) - Key Space 2^56 เล็กเกินไป
  • 3DES (Triple DES): ใช้ DES 3 รอบ (Effective 112-bit) ล้าสมัย ช้า ถูก Deprecated (NIST SP 800-131A) ห้ามใช้ใหม่หลัง 2023
  • AES (Advanced Encryption Standard - Rijndael): แทนที่ DES (2001) 128/192/256-bit Key, 128-bit Block, SP Network - มาตรฐานปัจจุบัน
  • ⚠️ หมายเหตุ: "DES" ในโจทย์อาจสับสนกับ Diethylstilbestrol (ยาโฮร์มอนสังเคราะห์) ซึ่งเป็นเรื่องยา ไม่เกี่ยวกับ Cryptography

สรุป: "K" ใน Network Security Encryption

  • มักหมายถึง Key (คีย์) โดยเฉพาะ DEK (Data Encryption Key) และ KEK (Key Encryption Key)
  • ทำความเข้าใจ Key Hierarchy (Root > KEK > DEK > Data) และ Envelope Encryption
  • ใช้ KMS/HSM จัดการคีย์ อย่า Hardcode/Store Keys ใน Code/Config/Repo
  • เลือก Algorithm ที่ทันสมัย: AES-256-GCM, ChaCha20-Poly1305 (Symmetric) | RSA-3072+/ECDSA P-256/Ed25519 (Asymmetric) | HKDF/Argon2 (KDF)
  • ปฏิบัติตาม NIST SP 800-57 (Key Management), FIPS 140-3 (HSM), PCI-DSS (Key Handling)