日期:2011-12-07 浏览次数:20438 次
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text,"MD5")进行MD5加密出来的结果却是:
'MD5 = LCase(WordToHex(a) & WordToHex(b) & WordToHex(c) & WordToHex(d)) MD5=LCase(WordToHex(b) & WordToHex(c)) 'I crop this to fit 16byte database password :D第一句是取全部的32位密文,第二句则是取中间第9~25位为16位密文。
'MD5 加密函数 Public Shared Function MD5(ByVal strSource As String, ByVal Code As Int16) As String '这里用的是ascii编码密码原文,如果要用汉字做密码,可以用UnicodeEncoding,但会与ASP中的MD5函数不兼容 Dim dataToHash As Byte() = (New System.Text.ASCIIEncoding).GetBytes(strSource) Dim hashvalue As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), System.Security.Cryptography.HashAlgorithm).ComputeHash(dataToHash) Dim i As Integer Select Case Code Case 16 '选择16位字符的加密结果 For i = 4 To 11 MD5 += Hex(hashvalue(i)).ToLower Next Case 32 '选择32位字符的加密结果 For i = 0 To 15 MD5 += Hex(hashvalue(i)).ToLower Next Case Else 'Code错误时,返回全部字符串,即32位字符 For i = 0 To hashvalue.Length - 1 MD5 += Hex(hashvalue(i)).ToLower Next End Select End Function