Function EncodePassword(ByVal pass As String, ByVal challange As String) As String
Dim hash_byte(challange.Length / 2 - 1) As Byte
For i = 0 To challange.Length - 2 Step 2
hash_byte(i / 2) = Byte.Parse(challange.Substring(i, 2), Globalization.NumberStyles.HexNumber)
Next
Dim response(pass.Length + hash_byte.Length) As Byte
response(0) = 0
Text.Encoding.ASCII.GetBytes(pass.ToCharArray()).CopyTo(response, 1)
hash_byte.CopyTo(response, 1 + pass.Length)
Dim md5 = New System.Security.Cryptography.MD5CryptoServiceProvider()
Dim hash = md5.ComputeHash(response)
Dim hashStr As New Text.StringBuilder()
For Each h In hash
hashStr.Append(h.ToString("x2"))
Next
Return hashStr.ToString()
End Function |