Comparing MD5 Hashed strings


I have some trouble comparing hashed strings between .Net and .Net Compact Framework. I used normal VB.NET to store a MD5 hashed string in a database. I used the following code to create and compare the same hash (at least, that is what i thought) using VB.NET Compact Framework (with a little help from OpenNetCF)

Dim clearBytes As [Byte]()
Dim MD5 As New MD5CryptoServiceProvider
Dim hashedText As String
Dim hashedBytes As [Byte]()
Dim str as string = "123"

clearBytes = Encoding.Unicode.GetBytes(str)
hashedBytes = MD5.ComputeHash(clearBytes)
hashedText = BitConverter.ToString(hashedBytes)

This produces the following Hash:


If I compare this to the same Hash i did with VB.NET (Using standard .Net Crypto Provider):


there is a difference.

Does anyone know how to fix this issue?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jetforceConnect With a Mentor Commented:


    Private Function ConvertHashProp(ByVal value As String) As String
        Dim strArr() As String = Split(value, "-")
        For i As Int16 = 0 To strArr.GetUpperBound(0) - 1
            If strArr(i).Length = 1 Then
                strArr(i) = "0" & strArr(i)
            End If

        Return Join(strArr, "-")
    End Function
the problem is is the value is less than 15 (hex F) then there is no prefix of 0
                              V                         V

If I compare this to the same Hash i did with VB.NET (Using standard .Net Crypto Provider):


There is two ways to do this
1)  find all the single figures and prefix them with a 0 and then do the compare

or split the string into an array by using the split variable as '-'
2)  then compare the values individually by converting them to an integer

All Courses

From novice to tech pro — start learning today.