最近真正统一了台州博客的通行证。这其中包括ASP(原旧博客站点),与ASP.NET(通行证让点),第二天更发生了用户不能登录的问题(中文ID),一直提供
MD5值错误(通行证使用MD5混合校验)。第一想到的就是ASP的GB2312编码和ASP.NET的UTF-8编码对中文MD5的问题,但最后才确认真正的问题不是页面编码,而是MD5加密编码的问题。找了很多资料,很多人都说歉容中文,但偶就是不行(前提是保持页面编码不变),最后突然想到URL编码后再加密,但效果是URL编码也分文字编码的。呵呵,不过最后还是用unicode编码搞定。
ASP
function chinese2unicode(str)
dim hexValue
dim one
for i=1 to len(str)
one=Mid(str,i,1)
hexValue=hexValue & Hex(asc(one))
next
chinese2unicode=hexValue
end function.NET
string Create16BitMd5Password(string password)
{
System.Text.Encoding gb = System.Text.Encoding.GetEncoding("gb2312");
byte[] temp = gb.GetBytes(password);
System.Text.StringBuilder result = new System.Text.StringBuilder();
foreach (byte one in temp)
{
result.Append(one.ToString("X"));
}
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(result.ToString(), "MD5").ToLower().Substring(8, 16);
} ASP 16位与32位 MD5
.NET 16位与32位 MD5
全文完