Hi,
Please refer below code.
protected void Page_Load(object sender, EventArgs e)
{
CompareHashValue("Data1", "Data2");
}
private bool CompareHashValue(string sSourceData, string sSourceData1)
{
byte[] tmpSource;
byte[] tmpHash;
tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData);
tmpHash = new MD5CryptoServiceProvider().ComputeHash(tmpSource);
tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData1);
byte[] tmpNewHash;
tmpNewHash = new MD5CryptoServiceProvider().ComputeHash(tmpSource);
bool bEqual = false;
if (tmpNewHash.Length == tmpHash.Length)
{
int i = 0;
while ((i < tmpNewHash.Length) && (tmpNewHash[i] == tmpHash[i]))
{
i += 1;
}
if (i == tmpNewHash.Length)
{
bEqual = true;
}
}
return bEqual;
}
static string ByteArrayToString(byte[] arrInput)
{
int i;
StringBuilder sOutput = new StringBuilder(arrInput.Length);
for (i = 0; i < arrInput.Length - 1; i++)
{
sOutput.Append(arrInput[i].ToString("X2"));
}
return sOutput.ToString();
}
VB
Protected Sub Page_Load(sender As Object, e As EventArgs)
CompareHashValue("Data1", "Data2")
End Sub
Private Function CompareHashValue(sSourceData As String, sSourceData1 As String) As Boolean
Dim tmpSource As Byte()
Dim tmpHash As Byte()
tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData)
tmpHash = New MD5CryptoServiceProvider().ComputeHash(tmpSource)
tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData1)
Dim tmpNewHash As Byte()
tmpNewHash = New MD5CryptoServiceProvider().ComputeHash(tmpSource)
Dim bEqual As Boolean = False
If tmpNewHash.Length = tmpHash.Length Then
Dim i As Integer = 0
While (i < tmpNewHash.Length) AndAlso (tmpNewHash(i) = tmpHash(i))
i += 1
End While
If i = tmpNewHash.Length Then
bEqual = True
End If
End If
Return bEqual
End Function
Private Shared Function ByteArrayToString(arrInput As Byte()) As String
Dim i As Integer
Dim sOutput As New StringBuilder(arrInput.Length)
For i = 0 To arrInput.Length - 2
sOutput.Append(arrInput(i).ToString("X2"))
Next
Return sOutput.ToString()
End Function
I hope this will help you out.