Solved

Comparing MD5 Hashed strings

Posted on 2004-09-10
2
1,059 Views
Last Modified: 2009-12-16
Hi,

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:

"5F-A2-85-E1-BE-BE-A-66-23-E3-3A-FC-4-A1-FB-D5"

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

"5F-A2-85-E1-BE-BE-0A-66-23-E3-3A-FC-04-A1-FB-D5"

there is a difference.

Does anyone know how to fix this issue?

BR, DM
0
Comment
Question by:Darq_Messiah
  • 2
2 Comments
 
LVL 3

Expert Comment

by:jetforce
ID: 12024882
the problem is is the value is less than 15 (hex F) then there is no prefix of 0
                              V                         V
"5F-A2-85-E1-BE-BE-A-66-23-E3-3A-FC-4-A1-FB-D5"

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

"5F-A2-85-E1-BE-BE-0A-66-23-E3-3A-FC-04-A1-FB-D5"


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

Jetforce
0
 
LVL 3

Accepted Solution

by:
jetforce earned 250 total points
ID: 12024916

      MsgBox(ConvertHashProp("5F-A2-85-E1-BE-BE-A-66-23-E3-3A-FC-4-A1-FB-D5"))


    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
        Next

        Return Join(strArr, "-")
    End Function
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question