Solved

Comparing MD5 Hashed strings

Posted on 2004-09-10
2
1,078 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import Data from Multiple Text Files in Excel 12 86
Data organization issue 7 39
Add Combobox column to datagridview using vb.net 2 27
Need help with another query 10 39
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

730 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