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

Hash (แฮช) ในความปลอดภัยเครือข่ายคืออะไร

Hash (ฟังก์ชันแฮช) ในความปลอดภัยเครือข่ายคืออะไร?

Hash Function (ฟังก์ชันแฮช) เป็นอัลกอริทึมทางคณิตศาสตร์ที่รับข้อมูลนำเข้า (Input) ขนาดไม่จำกัด แปลงเป็นค่าคงที่ (Fixed-length Output) เรียกว่า Hash Value, Hash Code, Digest, หรือ Checksum

คุณสมบัติสำคัญของ Cryptographic Hash Function

คุณสมบัติคำอธิบาย
DeterministicInput เดียวกัน ต้องได้ Hash เดียวกันทุกครั้ง
Pre-image Resistance (One-way)ไม่สามารถย้อนกลับจาก Hash หา Input ต้นฉบับได้ (Computationally Infeasible)
Second Pre-image Resistanceหา Input อีกตัวที่ให้ Hash เดียวกันได้ยาก
Collision Resistanceหา Input 2 ตัวที่ให้ Hash เดียวกันได้ยาก (Birthday Attack)
Avalanche Effectเปลี่ยน Input เพียง 1 บิต → Hash เปลี่ยนประมาณ 50% ของบิต
Fixed Output Lengthไม่ว่าขนาด Input จะใหญ่แค่ไหน Output คงที่ (เช่น SHA-256 = 256 บิต = 64 Hex chars)

อัลกอริทึมแฮชยอดนิยม

อัลกอริทึมขนาด Outputสถานะใช้งาน
MD5128-bit (32 hex)แตกแล้ว (Broken) - ห้ามใช้งานด้านความปลอดภัยChecksum ไฟล์ (Non-security), Legacy
SHA-1160-bit (40 hex)อ่อนแอ (Deprecated) - พบ Collision แล้วGit, TLS Certs (เก่า), Legacy
SHA-256256-bit (64 hex)มาตรฐานปัจจุบัน (Recommended)TLS, Bitcoin, Password Hashing (กับ Salt), Digital Signatures, Blockchain
SHA-384384-bitเข้มกว่า SHA-256High Security, TLS 1.3
SHA-512512-bitเข้มกว่า SHA-384High Security, Password Hashing
SHA-3 (Keccak)224/256/384/512รุ่นใหม่ โครงสร้างต่างจาก SHA-2Future-proof, Ethereum
BLAKE2/3Variableเร็วกว่า SHA-2/3 มากHigh Performance, Crypto Currencies

การใช้งาน Hash ในความปลอดภัย

  1. Password Storage: เก็บ Hash(Password + Salt) แทน Plaintext ใช้ Bcrypt, Argon2, PBKDF2, Scrypt (Slow Hash)
  2. Data Integrity: ตรวจสอบไฟล์ดาวน์โหลด (Checksum), Git Commits, Blockchain Transactions
  3. Digital Signatures: Hash(Document) + Sign with Private Key
  4. Certificate Fingerprints: SHA-256 ของ Certificate ใช้ Verify
  5. HMAC (Hash-based MAC): Message Authentication + Integrity (API Authentication, JWT)
  6. Key Derivation: HKDF, PBKDF2 สร้าง Key จาก Password/Secret
  7. Proof of Work: Bitcoin Mining (SHA-256d)

Hash vs Encryption

คุณสมบัติHash (One-way)Encryption (Two-way)
可逆性 (Reversibility)ไม่สามารถย้อนกลับได้สามารถถอดรหัสได้ด้วย Key
Keyไม่ใช้ Key (Unkeyed) *ยกเว้น HMACต้องใช้ Key (Symmetric/Asymmetric)
Output Lengthคงที่ขึ้นกับ Input + Padding
ใช้งานIntegrity, Authentication, PasswordConfidentiality (ความลับ)

ตัวอย่าง Hash Value (SHA-256)

Input: "Hello World"
SHA-256: a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e

Input: "Hello World!" (เพิ่ม ! เดียว)
SHA-256: 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069

สรุป

Hash เป็นรากฐานของความปลอดภัยดิจิทัล ใช้รับรอง Integrity (ความสมบูรณ์) และ Authentication (ความแท้จริง) ไม่ใช่สำหรับ Confidentiality (ความลับ) ต้องเลือกอัลกอริทึมที่เหมาะสม (SHA-256 ขึ้นไป) และใช้ Salt/Slow Hash สำหรับรหัสผ่าน