爬蟲模擬登入時發現:md5(h1) 與 md5(h1 + salt) 結果不同,但 salt = ""(空字串)。按理空字串不應影響 MD5 結果。
瀏覽器開發者工具顯示 salt = "",實際上 salt 是一個 長度為 8 的不可見控制字元/亂碼字串。控制台無法顯示這些字元,誤以為是空字串。
console.log(salt.length); // 輸出 8,非 0
console.log(salt.charCodeAt(0)); // 查看第一個字元編碼
console.log(JSON.stringify(salt)); // 可見轉義序列,如 "\u0001\u0002..."
import hashlib
h1 = "g\x8fn\xb7\xbfEA{3\xa9\xe4I\x84\xc7\x8f" # 實際位元組
salt = "\x01\x02\x03\x04\x05\x06\x07\x08" // 8 位元組亂碼
print(hashlib.md5(h1.encode('latin-1')).hexdigest())
print(hashlib.md5((h1 + salt).encode('latin-1')).hexdigest()) # 結果不同
.length、charCodeAt、JSON.stringify 檢查實際內容。