MD5 problem in vb 2010

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
12 posts Page 1 of 2
Contributors
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

MD5 problem in vb 2010
geenID
hello, I would like make a MD5-hash, but it will gives the following error (see screenshot)
Can somebody help me ?
(sorry for my bad english ;) )

Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: MD5 problem in vb 2010
mandai
You can't have a variable called default because that is a reserved keyword.
Also I can't see what your md5string function is referencing to.

This should probably do what you want:
Code: Select all
Dim myMD5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim data As Byte() = Encoding.ASCII.GetBytes("to protect")
Dim hash As Byte() = myMD5.ComputeHash(data)
For i As Integer = 0 To hash.Length - 1
     MsgBox("hash: byte " & i & " = " & hash(i))
Next
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: MD5 problem in vb 2010
geenID
Thanks, but it's not working, so I have here a better screenshot:

Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: MD5 problem in vb 2010
mandai
Looks like various syntax errors to me.

When you declare variables you should start with the Dim keyword.
As said before 'default' can't be used for a variable name.
You can't assign the statement 1 To 19 as a variable directly
And your md5string function is yet to be seen
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: MD5 problem in vb 2010
geenID
I have changed to code, So it's only have now 2 errors:


Image




Mirror:
http://img688.imageshack.us/img688/93/2errors.png
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: MD5 problem in vb 2010
geenID
So I hope somebody can resolve this 2 problems ... ?
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: MD5 problem in vb 2010
mandai
Yea its all about fixing the syntax really
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: MD5 problem in vb 2010
geenID
Yes you're right. I have not no more (syntax) errors, But if I debug, then it gives the follow error:

Image




Here is the whole code
Public Class Form1
Dim S(0 To 19)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim str1, str2, temp, temp1, temp2, temp3, temp4, temp5, temp6, L As String
Dim i

str2 = "GeenIDCreations"
str1 = "31330172046F07770A760D65106F1365166519301C2E1F2E22680265036F057306660874096D0B760C690E640F6F1163126E14761572177418721A321B301D381E31203221312336243030"

For i = 1 To Len(str1) / 2
temp = Mid(str1, (2 * i - 1), 2)
temp1 = temp1 & Chr("&H" & temp)
Next i


'-----------------------------------------------------------'

temp2 = ""
Dim var
var = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
L = Len(var)

For i = 1 To 19
S(i) = Mid(var, Rnd() * (L - 1) + 1, 1)
temp2 = temp2 & S(i)
Next i

'-----------------------------------------------------------'

Dim myMD5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim data As Byte() = Encoding.ASCII.GetBytes("to protect")
Dim hash As Byte() = myMD5.ComputeHash(data)

temp3 = Mid(temp2, 1, 4) & Mid(temp2, 5, 4) & Mid(temp2, 9, 4) & Mid(temp2, 13, 16)
temp4 = myMD5.Hash(temp1 & temp3 & str2)

temp6 = ""

For i = 1 To Len(temp4) / 2
temp5 = Mid(temp4, 2 * L - 1, 1)
temp6 = temp6 & temp5

Next i

TextBox1.Text = temp3 & Mid(temp6, 1, 4) & Mid(temp6, 5, 4) & Mid(temp6, 9, 4) & str2
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: MD5 problem in vb 2010
mandai
MD5.Hash is a property (of the byte array type) that would equal the same result from the ComputeHash function in this case.
You are getting that exception because you are telling VB to return a value out of this array at an invalid index.
User avatar
geenID
New Member
New Member
Posts: 15
Joined: Mon Dec 21, 2009 5:56 pm

Re: MD5 problem in vb 2010
geenID
Ok, but my english is not very good, and my visual basic knowledge also, so I don't now to change the code correctly.
Mayby you can?
12 posts Page 1 of 2
Return to “Coding Help & Support”