asp.net| function | Encryption in ASP, we used such as the Dynamic Network forum, such as the ASP MD5 function encrypted string is such as:
1165d25d8cd021d5
And in ASP.net, the following method: code
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (password. Text, "MD5")
The results of MD5 encryption 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.
No. 353, 354 lines in the ASP's MD5 function: code
' MD5 = LCase (Wordtohex (a) & Wordtohex (b) & Wordtohex (c) & Wordtohex (d)) Md5=lcase (Wordtohex (b) & Wordtohe X (c)) ' I crop this to fit 16byte database password:D
The first sentence is to take all 32-digit ciphertext, the second sentence is to take the middle 9th to 25th Digit is 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 cryptographic functions public Shared function MD5 (ByVal strsource As String, ByVal Code as Int16) As String ' here is the original ASCII encoded cipher, if you want to use Han Word to do the password, you can use UnicodeEncoding, but 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 ' select 16-bit encryption result for i = 4 to one M D5 + = Hex (HashValue (i)). ToLower Next Case ' Select the 32-bit encryption result for i = 0 to MD5 + = Hex (HashValue (i)). ToLower Next case Else ' code error, returns all strings, that is, 32-bit character for i = 0 to HashValue. Length-1 MD5 + = Hex (HashValue (i)). ToLower Next End Select End Function