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

Cryptography และ Network Security: หลักการ อัลกอริทึม และการประยุกต์ใช้

Cryptography (ทฤษฎีการเข้ารหัส) คืออะไร?

Cryptography คือวิทยาศาสตร์และศิลปะของการปกป้องข้อมูลโดยการแปลงข้อมูลเดิม (Plaintext) ให้กลายเป็นข้อมูลที่อ่านไม่ออก (Ciphertext) เพื่อให้เฉพาะฝ่ายที่ได้รับอนุญาต (มี Key) เท่านั้นที่สามารถกลับมาอ่านได้ (Decryption) เป้าหมายหลัก: Confidentiality, Integrity, Authentication, Non-repudiation

ความสัมพันธ์: Cryptography vs Network Security vs Cybersecurity

DomainFocusRelationship
CryptographyMathematical Techniques: Encryption, Hashing, Signatures, Key ExchangeFoundation / Building Block
Network SecurityProtect Data in Transit (Network Layer): TLS, IPsec, VPN, SSH, DNSSECApplies Crypto to Network Protocols
CybersecurityProtect All Digital Assets: Network, Endpoint, App, Cloud, Data, IdentityUmbrella 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

ProtocolPurposeCrypto Used
TLS 1.2/1.3 (HTTPS)Secure Web, APIECDHE (Key Exch), AES-GCM/ChaCha20-Poly1305 (AEAD), RSA/ECDSA/EdDSA (Auth)
IPsec (ESP/AH)VPN, Site-to-SiteIKEv2 (DH/ECDH), AES-GCM, SHA-256/384
SSHRemote Access, SFTPECDH, Ed25519, ChaCha20-Poly1305, AES-GCM
WireGuardModern VPNCurve25519 (DH), ChaCha20-Poly1305, BLAKE2s, HKDF
DNSSECDNS Integrity/AuthRSA/ECDSA, SHA-256, NSEC/NSEC3
S/MIME, PGP/GPGEmail Encryption/SignRSA/ECC, AES, SHA
KerberosAuth (Windows AD)AES, RC4 (Deprecated), SPNEGO
802.1X (EAP-TLS/PEAP)Network Access ControlTLS (Cert-based), MS-CHAPv2

หลักการพื้นฐานของ Cryptography & Network Security (CIA + Auth + Non-rep)

  1. Confidentiality: Encryption (Symmetric/Asymmetric/Hybrid)
  2. Integrity: Hash (HMAC), Authenticated Encryption (AES-GCM, ChaCha20-Poly1305), Digital Signature
  3. Availability: ไม่ใช่ Crypto โดยตรง แต่ Redundancy, DDoS Protection, Backup
  4. Authentication: Digital Signature, Certificates (PKI), MAC, Password/Token/Biometric
  5. Non-repudiation: Digital Signature (Private Key Sign → Public Key Verify), Audit Logs
  6. 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

  1. Encryption: Plaintext + Key → Ciphertext
  2. Decryption: Ciphertext + Key → Plaintext
  3. 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 ปี