Solved

Comparing MD5 Hashed strings

Posted on 2004-09-10
2
1,050 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now