If you take a look at the output you'll see that mySQL is returning 32
hexadecimal characters.

You'll see the ComputeHash function is returning 16 bytes, the base64
is converting it into 24 characters that are not limited to
hexadecimal range. But if you convert a byte into its hexidecimal
representation, you get 2 hexadecimal chars 16x2 = 32 j(don't forget
to keep the leading 0s.)

So what you need to do is convert each byte in bytHash to its
hexadecimal representation.

There is a probably a simplr way to this, but its late.

        Dim i As Integer
        For i = 0 To bytHash.Length - 1
            'don't lose the leading 0
            strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
        Next



On 10/4/05, Rick Holcomb <[EMAIL PROTECTED]> wrote:
> I am trying to calculate an MD5 checksum in .Net 2.0 and then
> compare it to the value I get from a MySQL query.
> The MySQL query always returns a 32 character value where as .Net
> 2.0 seems to always return a 24 character value.
> Is there any way to modify the .Net version to be compatible with
> MySQL?
>
> Here is my .Net code:
>
>         Dim md5 As MD5CryptoServiceProvider
>         Dim bytValue() As Byte
>         Dim bytHash() As Byte
>
>         ' Create New Crypto Service Provider Object
>         md5 = New MD5CryptoServiceProvider
>
>         ' Convert the original string to array of Bytes
>         bytValue = System.Text.Encoding.UTF8.GetBytes(strInput)
>
>         ' Compute the Hash, returns an array of Bytes
>         bytHash = md5.ComputeHash(bytValue)
>         md5.Clear()
>
>         ' Return a base 64 encoded string of the Hash value
>         strOutput = Convert.ToBase64String(bytHash)
>
>
>
>         ' MySQL returns 1bbd886460827015e5d605ed44252251
>         ' .Net returns G72IZGCCcBXl1gXtRCUiUQ==
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




Reply via email to