Hash Identifier
ระบุประเภท hash ตามความยาวและรูปแบบ — MD5, SHA-1, SHA-256 และอื่นๆ
สตริง Hash
การระบุ Hash คืออะไร?
การระบุ hash คือกระบวนการตรวจสอบว่าอัลกอริทึม hash เชิงการเข้ารหัสใดเป็นผู้สร้างไดเจสต์ที่กำหนด ฟังก์ชัน hash เชิงการเข้ารหัส เช่น MD5, SHA-1 และ SHA-256 ต่างสร้างผลลัพธ์ที่มีความยาวคงที่ และความยาวของผลลัพธ์คือสัญญาณหลักที่ใช้ระบุ hash ที่ไม่รู้จัก เมื่อพบสตริงฐานสิบหกในไฟล์ดัมพ์ฐานข้อมูล ไฟล์คอนฟิกูเรชัน หรือการตอบสนอง API เครื่องมือระบุ hash จะบอกว่าอัลกอริทึมใดมีแนวโน้มสร้างสตริงนั้น
อัลกอริทึม hash ทุกตัวจะแปลงข้อมูลอินพุตใด ๆ ให้เป็นผลลัพธ์ขนาดคงที่ที่เรียกว่าไดเจสต์ MD5 สร้างผลลัพธ์ 128 บิตเสมอ (32 อักขระ hex) SHA-1 สร้าง 160 บิตเสมอ (40 อักขระ hex) และ SHA-256 สร้าง 256 บิตเสมอ (64 อักขระ hex) ความยาวผลลัพธ์ที่แน่นอนนี้คือสิ่งที่ทำให้การระบุอัลกอริทึมเป็นไปได้โดยไม่ต้องเข้าถึงอินพุตเดิมหรือโค้ดการแฮช
การระบุจากความยาวเพียงอย่างเดียวอาจไม่ชัดเจนเสมอไป อัลกอริทึมหลายตัวมีขนาดผลลัพธ์เท่ากัน เช่น SHA-256 และ SHA3-256 ต่างสร้างไดเจสต์ hex 64 อักขระ ในกรณีเหล่านี้ เครื่องมือระบุ hash จะแสดงรายการอัลกอริทึมที่เป็นไปได้เรียงตามความพบบ่อย ข้อมูลบริบท เช่น ระบบต้นทาง รูปแบบการเข้ารหัส (hex กับ Base64) และการมีคำนำหน้าอัลกอริทึม (เช่น '$2b$' สำหรับ bcrypt) ช่วยลดความเป็นไปได้ให้แคบลง
เหตุใดจึงควรใช้เครื่องมือระบุ Hash?
hash ที่ไม่รู้จักปรากฏขึ้นเป็นประจำระหว่างการตรวจสอบความปลอดภัย การโยกย้ายฐานข้อมูล และการวิเคราะห์นิติวิทยาศาสตร์ดิจิทัล เครื่องมือระบุ hash ขจัดการเดาสุ่มและชี้ไปยังอัลกอริทึมที่ถูกต้องภายในไม่กี่วินาที
กรณีการใช้งานเครื่องมือระบุ Hash
ตารางอ้างอิงความยาวอัลกอริทึม Hash
ตารางด้านล่างแมปอัลกอริทึม hash ทั่วไปแต่ละตัวกับขนาดผลลัพธ์เป็นบิต อักขระ hex และไบต์ดิบ นี่คือตารางค้นหาหลักที่เครื่องมือระบุ hash ใช้งาน เมื่ออัลกอริทึมหลายตัวมีความยาว hex เท่ากัน คุณจะต้องใช้บริบทเพิ่มเติมเพื่อแยกความแตกต่าง
| อัลกอริทึม | บิต | อักขระ Hex | ไบต์ | หมายเหตุ |
|---|---|---|---|---|
| MD5 | 128 | 32 | 16 | Broken — collisions trivial since 2004 |
| SHA-1 | 160 | 40 | 20 | Deprecated — SHAttered attack (2017) |
| SHA-224 | 224 | 56 | 28 | Truncated SHA-256; rarely used standalone |
| SHA-256 | 256 | 64 | 32 | Current standard; TLS, Git, Bitcoin |
| SHA-384 | 384 | 96 | 48 | Truncated SHA-512; CNSA Suite approved |
| SHA-512 | 512 | 128 | 64 | Maximum SHA-2 output; large-data hashing |
| SHA3-256 | 256 | 64 | 32 | Keccak-based; NIST alternative to SHA-2 |
| SHA3-512 | 512 | 128 | 64 | Keccak-based; highest SHA-3 strength |
| RIPEMD-160 | 160 | 40 | 20 | Used in Bitcoin address derivation |
| BLAKE2s | 256 | 64 | 32 | Faster than SHA-256; 256-bit output |
การแก้ไขความกำกวมของความยาว Hash
ความยาว hex บางอย่างตรงกับอัลกอริทึมหลายตัว ความกำกวมที่พบบ่อยที่สุดสองกรณีคือ hash 64 อักขระ (SHA-256 กับ SHA3-256) และ hash 40 อักขระ (SHA-1 กับ RIPEMD-160) ต่อไปนี้คือวิธีแยกความแตกต่างเมื่อความยาวเพียงอย่างเดียวไม่เพียงพอ
ตัวอย่างโค้ด
ด้านล่างคือการติดตั้งใช้งานจริงของการระบุ hash ตามความยาว hex ในสี่ภาษา แต่ละฟังก์ชันตรวจสอบการเข้ารหัส hex ค้นหาจำนวนอักขระ และส่งคืนอัลกอริทึมที่ตรงกันทั้งหมด
function identifyHash(hex) {
const len = hex.length
const isHex = /^[0-9a-fA-F]+$/.test(hex)
if (!isHex) return ['Not a hex-encoded hash']
const map = {
32: ['MD5'],
40: ['SHA-1', 'RIPEMD-160'],
56: ['SHA-224', 'SHA3-224'],
64: ['SHA-256', 'SHA3-256', 'BLAKE2s'],
96: ['SHA-384', 'SHA3-384'],
128: ['SHA-512', 'SHA3-512', 'BLAKE2b'],
}
return map[len] || [`Unknown (${len} hex chars)`]
}
identifyHash('d41d8cd98f00b204e9800998ecf8427e')
// → ["MD5"]
identifyHash('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
// → ["SHA-256", "SHA3-256", "BLAKE2s"]import re
HASH_LENGTHS = {
32: ['MD5'],
40: ['SHA-1', 'RIPEMD-160'],
56: ['SHA-224', 'SHA3-224'],
64: ['SHA-256', 'SHA3-256', 'BLAKE2s'],
96: ['SHA-384', 'SHA3-384'],
128: ['SHA-512', 'SHA3-512', 'BLAKE2b'],
}
def identify_hash(hex_string: str) -> list[str]:
hex_string = hex_string.strip()
if not re.fullmatch(r'[0-9a-fA-F]+', hex_string):
return ['Not a hex-encoded hash']
return HASH_LENGTHS.get(len(hex_string), [f'Unknown ({len(hex_string)} hex chars)'])
identify_hash('da39a3ee5e6b4b0d3255bfef95601890afd80709')
# → ['SHA-1', 'RIPEMD-160']
identify_hash('a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a')
# → ['SHA-256', 'SHA3-256', 'BLAKE2s']package main
import (
"fmt"
"regexp"
)
var hexPattern = regexp.MustCompile("^[0-9a-fA-F]+$")
var hashLengths = map[int][]string{
32: {"MD5"},
40: {"SHA-1", "RIPEMD-160"},
56: {"SHA-224", "SHA3-224"},
64: {"SHA-256", "SHA3-256", "BLAKE2s"},
96: {"SHA-384", "SHA3-384"},
128: {"SHA-512", "SHA3-512", "BLAKE2b"},
}
func identifyHash(hex string) []string {
if !hexPattern.MatchString(hex) {
return []string{"Not a hex-encoded hash"}
}
if algos, ok := hashLengths[len(hex)]; ok {
return algos
}
return []string{fmt.Sprintf("Unknown (%d hex chars)", len(hex))}
}
func main() {
fmt.Println(identifyHash("d41d8cd98f00b204e9800998ecf8427e"))
// → [MD5]
}#!/bin/bash
# Identify a hash from the command line by character count
hash="$1"
if [[ ! "$hash" =~ ^[0-9a-fA-F]+$ ]]; then
echo "Not a hex-encoded hash"
exit 1
fi
len=${#hash}
case $len in
32) echo "MD5 (128-bit)" ;;
40) echo "SHA-1 or RIPEMD-160 (160-bit)" ;;
56) echo "SHA-224 or SHA3-224 (224-bit)" ;;
64) echo "SHA-256 or SHA3-256 (256-bit)" ;;
96) echo "SHA-384 or SHA3-384 (384-bit)" ;;
128) echo "SHA-512 or SHA3-512 (512-bit)" ;;
*) echo "Unknown hash length: $len chars" ;;
esac
# Usage: ./identify.sh d41d8cd98f00b204e9800998ecf8427e
# → MD5 (128-bit)