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

MD5 ในความปลอดภัยเครือข่ายคืออะไร?

MD5 (Message Digest Algorithm 5) คืออะไร?

MD5 เป็นฟังก์ชันแฮช (Hash Function) ที่รับข้อมูลขนาดใดก็ได้ และสร้างค่าแฮช (Hash Value / Digest) ขนาดคงที่ 128-bit (16 ไบต์ / 32 ตัวอักษร Hexadecimal) พัฒนาโดย Ronald Rivest ปี 1991

คุณสมบัติของฟังก์ชันแฮชที่ดี

  • Deterministic: Input เดียวกัน → Output เดียวกันเสมอ
  • Fast Computation: คำนวณได้รวดเร็ว
  • Pre-image Resistance: ไม่สามารถย้อนกลับหา Input จาก Hash ได้
  • Collision Resistance: หา Input 2 ชุดที่ให้ Hash เดียวกันได้ยาก (แต่ MD5 แตกแล้ว)
  • Avalanche Effect: เปลี่ยน Input เล็กน้อย → Hash เปลี่ยนมาก

MD5 ทำงานอย่างไร? (ภาพรวม)

  1. Padding: เพิ่มบิต 1 แล้วตามด้วย 0 จนความยาว ≡ 448 (mod 512)
  2. Append Length: บันทึกความยาวข้อความต้นฉบับ 64 บิต ท้ายข้อมูล
  3. Initialize Buffer: 4 รีจิสเตอร์ 32-bit (A=0x67452301, B=0xEFCDAB89, C=0x98BADCFE, D=0x10325476)
  4. Process 512-bit Blocks: 4 รอบ (Rounds) รอบละ 16 ขั้นตอน ใช้ Non-linear Functions (F, G, H, I)
  5. Output: รวม A,B,C,D → 128-bit Hash

การใช้งาน MD5 ในปัจจุบัน (Legacy / Non-cryptographic)

การใช้งานเหมาะสม?ตัวอย่าง
ตรวจสอบความสมบูรณ์ไฟล์ (File Integrity Check)✅ ใช่ได้เช็ค ISO, Firmware, Download ไฟล์ใหญ่
Checksum สำหรับ Non-security purposes✅ ใช่ได้Deduplication, Indexing, Git (ร่วมกับ SHA-1)
Password Hashing❌ ห้ามใช้เร็วเกินไป ไม่มี Salt → Rainbow Table, GPU Brute-force
Digital Signature / SSL Certificate❌ ห้ามใช้Collision Attack ทำได้จริง (2004~), CA หยุดออก Cert MD5 แล้ว
HMAC-MD5⚠️ ไม่แนะนำใหม่ยังไม่มีการโจมตีจริงแต่อยู่ในขีดเสี่ยง → ใช้ HMAC-SHA256 แทน

ทำไม MD5 จึงไม่ปลอดภัยสำหรับ Cryptography?

  • Collision Attack: หา Input 2 ชุดที่ Hash เดียวกันได้ (Wang et al. 2004, Stevens et al. 2012 - ช็อกภาพถ่าย)
  • Chosen-prefix Collision: สร้าง Certificate ที่ดูเหมือนกันแต่ Key ต่างกัน (2009 - Rogue CA)
  • Speed: GPU รุ่นใหม่คำนวณ MD5 ได้ ~200-300 GH/s → Brute-force ง่าย
  • NIST Deprecated: NIST SP 800-131A ระบุว่า MD5 Disallowed สำหรับ Digital Signature, SSL/TLS Certs, Key Derivation

ตัวเลือกที่ดีกว่า (Modern Alternatives)

อัลกอริทึมขนาด Hashใช้สำหรับ
SHA-256 (SHA-2)256-bitGeneral Purpose, TLS, Bitcoin, Git, Password (w/ Salt + Iterations)
SHA-3 (Keccak)224-512-bitAlternative to SHA-2, Different internal structure
BLAKE2b / BLAKE3256-512-bitFast, Secure, Modern (WireGuard, Restic, Argon2)
Argon2idConfigurablePassword Hashing (Winner PHC 2015)
bcrypt192-bitPassword Hashing (Classic, ยังดีอยู่)
PBKDF2ConfigurablePassword Hashing (FIPS, Legacy Systems)

คำสั่งตรวจสอบ MD5 Checksum

# Windows (PowerShell)
Get-FileHash -Algorithm MD5 file.iso

# Windows (cmd) - certutil
certutil -hashfile file.iso MD5

# Linux/macOS
md5sum file.iso
# หรือ
openssl dgst -md5 file.iso

สรุป

MD5 ล้าสมัยและไม่ปลอดภัยสำหรับ Cryptography (Password, Cert, Signature) แต่ ยังใช้ได้สำหรับ File Integrity Check แบบ Non-security สำหรับงานใหม่ ให้ใช้ SHA-256, SHA-3, BLAKE2/3 และสำหรับ Password ให้ใช้ Argon2id, bcrypt, PBKDF2 เท่านั้น