FormsAuthentication.HashPasswordForStoringInConfigFile 與 ASP MD5() 結果一致(大小寫差異)。根因:ASP.NET 預設 UTF-8,經典 ASP 預設 GB2312,編碼不同導致雜湊不同。
// 產生與 ASP (GB2312) 相同結果
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string result = BitConverter.ToString(
md5.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes("木子屋"))
).Replace("-", "");
// 結果: 0A40A90190DA023AE7AA17771663A41E
// 產生 UTF-8 結果 (與 FormsAuthentication 一致)
string resultUtf8 = BitConverter.ToString(
md5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes("木子屋"))
).Replace("-", "");
// 結果: 34D9CBD5164C47058DFA3AF832E2D1DC
Request 取得參數即亂碼,加密無意義。建議:統一全站編碼(`