Results 1 to 11 of 11

Thread: Md5

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176

    Md5

    I need to compute MD5 digest on a given string. How can i do this without using any other DLL's (it's in the framework, i'm quite sure).

    I already checked on MSDN and found a howto but i still don't get how to get digets...

    Any help is very welcome...
    JpEgy

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You can use the ComputeHash method of the System.Security.Cryptography.MD5CryptoServiceProvider class. You may have to convert the string to a byte array first.
    You can do that with the System.Text.ASCIIEncoding.GetBytes method.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    Yeah i tried that but somehow it just returns a string of strange chars which is 5 chars long while it has to return something that's like 25 long and just contains of numbers
    JpEgy

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    The MD5 hash should be 128 bits long.

    From the w3c website :

    The MD5 algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA or PGP.

    I tested it with the procedure below, and the ComputeHash method always returns an array with 16 elements, so it always returns a 128 bit value.
    I couldn't find anywhere that the result of an MD5 hash must be numeric.

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim md5c As New System.Security.Cryptography.MD5CryptoServiceProvider()
    3.         Dim asc As New System.Text.ASCIIEncoding()
    4.         Dim sTest As String = Me.TextBox1.Text
    5.         Dim bBuff() As Byte = asc.GetBytes(sTest)
    6.         Dim bHash() As Byte = md5c.ComputeHash(bBuff)
    7.         Dim sHash As String = asc.GetString(bHash)
    8.         MsgBox((bHash.GetUpperBound(0) + 1).ToString)
    9.         Me.Label1.Text = sHash
    10.     End Sub

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    OK, didn;t work.

    Server sends: USR 9 MD5 S 1019597611.24027
    Server sends MD5 Hash
    Client sends: USR 10 MD5 S ^5)d}e mW4@[t
    Client sends MD5 equivalent of the MD5 hash

    That's what my little proggy sends when using that code.

    Server sends: USR 9 MD5 S 1019597808.28149
    Server sends MD5 Hash
    Client sends: USR 10 MD5 S 1e3e24cba1f2e41d4ecc8d5d514272fc
    Client sends MD5 equivalent of the MD5 hash

    The problem is that the good code is made using a DLL. And since the framework should be able to do it by itself i would rather use the framework. What am i doing wrong??

    Thnx
    JpEgy

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    umm

    whats MD5

    i feel dumb
    Magiaus

    If I helped give me some points.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    Read this site and you'll be an expert very soon
    JpEgy

  8. #8
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    very cool

    Magiaus

    If I helped give me some points.

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    Originally posted by JpEgy
    OK, didn;t work.

    Server sends: USR 9 MD5 S 1019597611.24027
    Server sends MD5 Hash
    Client sends: USR 10 MD5 S ^5)d}e mW4@[t
    Client sends MD5 equivalent of the MD5 hash

    That's what my little proggy sends when using that code.

    Server sends: USR 9 MD5 S 1019597808.28149
    Server sends MD5 Hash
    Client sends: USR 10 MD5 S 1e3e24cba1f2e41d4ecc8d5d514272fc
    Client sends MD5 equivalent of the MD5 hash

    The problem is that the good code is made using a DLL. And since the framework should be able to do it by itself i would rather use the framework. What am i doing wrong??

    Thnx
    Do you mean that instead of ^5)d}e mW4@[t you want to have the result like 1e3e24cba1f2e41d4ecc8d5d514272fc?

    Then you have to format it in hex format.

    eg.
    VB Code:
    1. Dim md5c As New System.Security.Cryptography.MD5CryptoServiceProvider()
    2.         Dim asc As New System.Text.ASCIIEncoding()
    3.         Dim sTest As String = Me.TextBox1.Text
    4.         Dim bBuff() As Byte = asc.GetBytes(sTest)
    5.         Dim sResult As String
    6.         bBuff = md5c.ComputeHash(bBuff)
    7.         Dim i As Short
    8.         For i = LBound(bBuff) To UBound(bBuff)
    9.             sResult &= Hex(bBuff(i)).PadLeft(2, "0")
    10.         Next
    11.         Me.TextBox2.Text = sResult

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176

    aaaaaahhhhh

    AAHHHHH i didn't notice that DLL made a hex of it!!!! i feel so incredibly dump now!!! grrrrrr

    Anyway thank you very much !
    JpEgy

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Guess....i have wooden shoes, in my free time i sell tulips and I live in a huge windmill...
    Posts
    176
    OK, it's done

    The last thing that needed to be done was making the string lowercase, just in anyone wants to try it.
    JpEgy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width