In ASP, we have used such as the Dynamic Network forum, such as the MD5 function in ASP encrypted string, such as:
1165d25d8cd021d5
In the ASP.net, the following method:
Code System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (password. Text, "MD5") for MD5 encryption results are:
12c403b91165d25d8cd021d5f9b5bb7f
The reason is because, in the ASP, the MD5 function is to use the 9th to 25th digit in the 32-bit MD5 HashValue to write for ciphertext. Knowing this, the asp.net results can be used to compare the password strings in the old database.
In the ASP's MD5 function, line No. 353 and 354:
Code ' 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 The first sentence is to take all 32-bit ciphertext, and the second sentence is to take the 9th to 25th place in the middle to 16 Bit cipher text.
To the vb.net problem again, in vb.net, can not use the System.Web.Security namespace, can not use the above simple method for MD5 encryption. I write the following function to handle:
VB.net:
Code ' MD5 encryption function
Public Shared Function MD5 (ByVal strsource As String, ByVal Code as Int16) as String
' Here is the original ASCII code password, if you want to use Chinese characters to do the password, you can use UnicodeEncoding, but it will be incompatible with the MD5 function in ASP
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 ' Select the 16-bit encryption result
For i = 4 to 11
MD5 + = Hex (HashValue (i)). ToLower
Next
Case 32 ' Select the 32-bit encryption result
For i = 0 to 15
MD5 + = Hex (HashValue (i)). ToLower
Next
Case Else ' Code error, returns all strings, that is, 32-bit characters
For i = 0 to HashValue. Length-1
MD5 + = Hex (HashValue (i)). ToLower
Next
End Select
End Function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.