Get and check MD5
Public Class MainClass
Public Shared Function GetMD5Hash(ByVal Text As String) As Byte()
Dim objAscii As New System.Text.ASCIIEncoding()
Dim bytHash As Byte() = New System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(objAscii.GetBytes(Text))
Return bytHash
End Function
Public Function CheckMD5Hash(ByVal OriginalHash As Byte(), ByVal Text As String) As Boolean
Dim objAscii As New System.Text.ASCIIEncoding()
Dim intCount As Integer, blnMismatch As Boolean
Dim bytHashToCompare As Byte() = GetMD5Hash(Text)
If OriginalHash.Length <> bytHashToCompare.Length Then
Return False
Else
For intCount = 0 To OriginalHash.Length
If OriginalHash(intCount) <> bytHashToCompare(intCount) Then
Return False
End If
Next
Return True
End If
End Function
Public Sub Main()
Dim bytHash() As Byte = GetMD5Hash("password")
System.Console.WriteLine(CheckMD5Hash(bytHash, "password"))
End Sub
End Class
Related examples in the same category