Hashing ใน Network Security คืออะไร?
กระบวนการแปลงข้อมูลขนาดใหญ่ (Input) ให้เป็นค่าคงที่ (Fixed-length Output) เรียกว่า Hash Value / Digest / Checksum ด้วยฟังก์ชันทางคณิตศาสตร์ (Hash Function) ซึ่งเป็น One-way Function (ย้อนกลับไม่ได้)
ทำไม Hashing จึงสำคัญต่อความปลอดภัย?
- Data Integrity (ความสมบูรณ์ของข้อมูล): ตรวจสอบว่าไฟล์/ข้อความ ไม่ถูกเปลี่ยนแปลง เสียหาย หรือถูก竄改 (Tampering) เปรียบเทียบ Hash ก่อน/หลังส่ง
- Password Storage: ไม่เก็บ Password แบบ Plaintext เก็บ Hash (Salted Hash) แทน หาก Database รั่ว โจมตีไม่ได้ Password จริงง่าย (ต้อง Crack)
- Digital Signatures: Hash ข้อมูล แล้ว Sign ด้วย Private Key ผู้รับ Verify ด้วย Public Key รับรอง Integrity + Authenticity + Non-repudiation
- Certificate & PKI: Certificate ถูก Hash แล้ว Sign โดย CA ใช้ใน TLS/SSL, Code Signing, Document Signing
- Blockchain & Merkle Trees: Hash เชื่อมโยง Block ตรวจสอบ Integrity ของ Ledger ทั้งหมด
- File/Software Verification: ดาวน์โหลดไฟล์ ตรวจสอบ Hash (SHA-256) กับที่ Publisher ให้มา
- Deduplication & Caching: ใช้ Hash เป็น Key ระบุ Unique Content (Git, Docker, CDN, Backup)
Hash Algorithms มาตรฐานในปัจจุบัน
| Algorithm | Output Size | สถานะ | ใช้งาน |
|---|---|---|---|
| SHA-256 (SHA-2) | 256-bit (64 hex) | มาตรฐานปัจจุบัน ✅ | TLS, Bitcoin, Git, Password Hashing (with Salt), Code Signing |
| SHA-384 / SHA-512 | 384/512-bit | มาตรฐาน ✅ | High-security, Long-term Integrity |
| SHA-3 (Keccak) | 224-512-bit | มาตรฐานใหม่ ✅ | Future-proof, Different internal structure from SHA-2 |
| BLAKE2 / BLAKE3 | 256/512-bit | Fast, Modern ✅ | File Integrity, Password Hashing (Argon2 uses BLAKE2) |
| MD5 | 128-bit | ❌ Broken (Collision) | Legacy only (Non-security: Checksums) |
| SHA-1 | 160-bit | ❌ Broken (Collision) | Legacy only (Git uses for object ID, not security) |
Password Hashing: ต้องใช้ Algorithm เฉพาะ (Slow Hash)
SHA-256 ไม่เหมาะสม สำหรับเก็บ Password เพราะเร็วเกินไป (GPU คำนวณได้พันล้าน/rounds ต่อวินาที) ต้องใช้:
- Argon2id (Winner Password Hashing Competition 2015) - Memory-hard, Tunable
- bcrypt - Work Factor ปรับได้, ใช้กันกว้าง
- scrypt - Memory-hard
- PBKDF2 - ไม่ Memory-hard แต่ยอมรับใน Compliance (FIPS)
Hashing ไม่ให้ Confidentiality (ความลับ)
Hashing เป็น One-way ไม่มี Key ใครก็คำนวณ Hash ได้ หากต้องการความลับ ต้องใช้ Encryption (AES, ChaCha20) Hashing ให้ Integrity และ Authentication (ผ่าน HMAC, Digital Signature)
HMAC (Hash-based Message Authentication Code)
Hash + Secret Key = HMAC ใช้ตรวจสอบ Integrity + Authenticity พร้อมกัน (ใช้ใน JWT, API Auth, TLS, IPsec)
Digital Forensics & Hash Values
- คำนวณ Hash (SHA-256) ของ Evidence (Disk Image, File) ทันทีที่จับได้ (Acquisition)
- บันทึก Hash ใน Chain of Custody
- Verify Hash ทุกขั้นตอน (Analysis, Court) รับรองว่า Evidence ไม่ถูกแก้ไข
- Deterministic: Input เดียวกัน → Hash เดียวกันเสมอ ใช้ Index/Database ได้เร็ว
สรุป
Hash Generators/Functions เป็นรากฐานของ Network Security: Integrity Verification, Password Protection, Digital Signatures, PKI/TLS, Blockchain, Forensics, Deduplication ต้องเลือก Algorithm ให้เหมาะสม (SHA-2/3 สำหรับ General, Argon2id/bcrypt สำหรับ Password) และจัดการ Key/Secret อย่างปลอดภัย