Tutorials to .com

Tutorials to .com » Asp » Skills » On ASP, ASP.NET, VB.NET's MD5 encryption function

On ASP, ASP.NET, VB.NET's MD5 encryption function

Print View , by: iSee ,Total views: 34 ,Word Count: 440 ,Date: Sat, 22 Aug 2009 Time: 10:09 AM

In ASP, we used such as ASP, etc.in MD5 encryption function is a string such as:
1165d25d8cd021d5

Asp.Net in the following ways:
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile (password.Text, "MD5")
MD5 encryption for the results, however, is:
12C403B91165D25D8CD021D5F9B5BB7F

The reason for this is because, in the asp of the MD5 function is to use a 32-bit MD5 Hashvalue the first 9 to 25 and then change lowercase as ciphertext. Aware of this reason, the results of ASP.NET can be used to handle a little older database password in a string.
MD5 function in the ASP of 353,354 in the first line:
'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 from the full 32-bit ciphertext, the second sentence is from the middle of the first 9 to 25 for 16-bit ciphertext.

vb.net problem to come in vb.net, the System.Web.Security namespace can not be used, can not be above simple MD5 encryption method. So I wrote this function to deal with the following:

VB.NET:
'MD5 encryption function
Public Shared Function MD5 (ByVal strSource As String, ByVal Code As Int16) As String
'Here is the ascii code of the original password, if the use of Chinese characters so the password can be used UnicodeEncoding, but with ASP the MD5 function is not compatible
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 16-bit encryption characters results
For i = 4 To 11
MD5 + = Hex (hashvalue (i)). ToLower
Next
Case 32 'characters to choose 32-bit encryption results
For i = 0 To 15
MD5 + = Hex (hashvalue (i)). ToLower
Next
Case Else 'Code error, the return of all the strings, that is 32 characters
For i = 0 To hashvalue.Length - 1
MD5 + = Hex (hashvalue (i)). ToLower
Next
End Select
End Function

Source: AndyDavis BLOG


ASP skills Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.