|
Thread: Md5
-
Apr 22nd, 2002, 03:53 PM
#1
Thread Starter
Addicted Member
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...
-
Apr 23rd, 2002, 01:53 AM
#2
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.
-
Apr 23rd, 2002, 10:23 AM
#3
Thread Starter
Addicted Member
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
-
Apr 23rd, 2002, 12:46 PM
#4
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim md5c As New System.Security.Cryptography.MD5CryptoServiceProvider()
Dim asc As New System.Text.ASCIIEncoding()
Dim sTest As String = Me.TextBox1.Text
Dim bBuff() As Byte = asc.GetBytes(sTest)
Dim bHash() As Byte = md5c.ComputeHash(bBuff)
Dim sHash As String = asc.GetString(bHash)
MsgBox((bHash.GetUpperBound(0) + 1).ToString)
Me.Label1.Text = sHash
End Sub
-
Apr 23rd, 2002, 04:43 PM
#5
Thread Starter
Addicted Member
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
-
Apr 23rd, 2002, 04:48 PM
#6
Frenzied Member
umm
whats MD5
i feel dumb
Magiaus
If I helped give me some points.
-
Apr 23rd, 2002, 05:58 PM
#7
Thread Starter
Addicted Member
Read this site and you'll be an expert very soon
-
Apr 24th, 2002, 12:09 AM
#8
Frenzied Member
Magiaus
If I helped give me some points.
-
Apr 24th, 2002, 01:12 AM
#9
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:
Dim md5c As New System.Security.Cryptography.MD5CryptoServiceProvider()
Dim asc As New System.Text.ASCIIEncoding()
Dim sTest As String = Me.TextBox1.Text
Dim bBuff() As Byte = asc.GetBytes(sTest)
Dim sResult As String
bBuff = md5c.ComputeHash(bBuff)
Dim i As Short
For i = LBound(bBuff) To UBound(bBuff)
sResult &= Hex(bBuff(i)).PadLeft(2, "0")
Next
Me.TextBox2.Text = sResult
-
Apr 24th, 2002, 10:55 AM
#10
Thread Starter
Addicted Member
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 !
-
Apr 25th, 2002, 06:33 AM
#11
Thread Starter
Addicted Member
OK, it's done
The last thing that needed to be done was making the string lowercase, just in anyone wants to try it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|