Solved

Comparing MD5 Hashed strings

Posted on 2004-09-10
2
1,039 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

10 Experts available now in Live!

Get 1:1 Help Now