md5
-
I'm having problems trying to hash a password in Visual Basic NET. The result of my code is different that the result of my php page. My VBNET code is this
Dim md5 As MD5CryptoServiceProvider Dim bytValue() As Byte Dim bytHash() As Byte md5 = New MD5CryptoServiceProvider bytValue = System.Text.Encoding.UTF8.GetBytes(txtPassword.Text) bytHash = md5.ComputeHash(bytValue) md5.Clear() messagebox.show(Convert.ToBase64String(bytHash))
The result is "bXOF/9d64JOf/waR9/mEFQ==" In PHP with his simple codeecho md5($password);
shows "6d7385ffd77ae0939fff0691f7f98415" Maybe anyone can say me why is different? Wich is the good VB code to show the same that in PHP? Thanks in advance -
I'm having problems trying to hash a password in Visual Basic NET. The result of my code is different that the result of my php page. My VBNET code is this
Dim md5 As MD5CryptoServiceProvider Dim bytValue() As Byte Dim bytHash() As Byte md5 = New MD5CryptoServiceProvider bytValue = System.Text.Encoding.UTF8.GetBytes(txtPassword.Text) bytHash = md5.ComputeHash(bytValue) md5.Clear() messagebox.show(Convert.ToBase64String(bytHash))
The result is "bXOF/9d64JOf/waR9/mEFQ==" In PHP with his simple codeecho md5($password);
shows "6d7385ffd77ae0939fff0691f7f98415" Maybe anyone can say me why is different? Wich is the good VB code to show the same that in PHP? Thanks in advanceMd5 results in a 128-bit number, php's function displays this in hexadecimal this is not the same as using ToBase64String. I don't know if there is a better way but this seemed to work
Dim md5 As MD5CryptoServiceProvider Dim bytValue() As Byte Dim bytHash() As Byte Dim sb As StringBuilder = New StringBuilder(32) Dim i As Integer md5 = New MD5CryptoServiceProvider bytValue = System.Text.Encoding.UTF8.GetBytes(txtPassword.Text) bytHash = md5.ComputeHash(bytValue) md5.Clear() For i = 0 To bytHash.Length - 1 sb.Append(bytHash(i).ToString("x")) Next MessageBox.Show(sb.ToString())
-
Md5 results in a 128-bit number, php's function displays this in hexadecimal this is not the same as using ToBase64String. I don't know if there is a better way but this seemed to work
Dim md5 As MD5CryptoServiceProvider Dim bytValue() As Byte Dim bytHash() As Byte Dim sb As StringBuilder = New StringBuilder(32) Dim i As Integer md5 = New MD5CryptoServiceProvider bytValue = System.Text.Encoding.UTF8.GetBytes(txtPassword.Text) bytHash = md5.ComputeHash(bytValue) md5.Clear() For i = 0 To bytHash.Length - 1 sb.Append(bytHash(i).ToString("x")) Next MessageBox.Show(sb.ToString())
Thanks a lot!! The code not works completely, but it's very close. Every time you append the text, sb is 2 characters longer. The problem appears when the bythash(i).toString("x") returns 1 character. VBNET "6d 73 85 ff d7 7a e0 93 9f ff 6 91 f7 f9 84 15" PHP "6d 73 85 ff d7 7a e0 93 9f ff 06 91 f7 f9 84 15" How is the clever way to always return 2 characters? How can I format this? NOTE: My txtpassword.text is "pasa"
-
Thanks a lot!! The code not works completely, but it's very close. Every time you append the text, sb is 2 characters longer. The problem appears when the bythash(i).toString("x") returns 1 character. VBNET "6d 73 85 ff d7 7a e0 93 9f ff 6 91 f7 f9 84 15" PHP "6d 73 85 ff d7 7a e0 93 9f ff 06 91 f7 f9 84 15" How is the clever way to always return 2 characters? How can I format this? NOTE: My txtpassword.text is "pasa"
A workaround is this
For i = 0 To bytHash.Length - 1 str = bytHash(i).ToString("x") If str.Length = 1 Then str = "0" & bytHash(i).ToString("x") End If sb.Append(str) Next
But there is a clever way for sure. Anybody? -
A workaround is this
For i = 0 To bytHash.Length - 1 str = bytHash(i).ToString("x") If str.Length = 1 Then str = "0" & bytHash(i).ToString("x") End If sb.Append(str) Next
But there is a clever way for sure. Anybody?Try using ToString("x2") that should do the same as your workaround.