doctor069
asked on
PHP MD5 Hash and .net MD5 not matching
Hi-
I have to get data from an external PHP site to my .net site.
The developer uses the following PHP code to get a hash:
$var1=1318437972;
$var2=01CdzTgUNgxIg;
md5(md5($var1). $var2)
Hash=06b27a58c07faee223d69 ca9e4a8716 3
I am trying to get the same hash in vb .net but the hashes are different:
Dim var1 As String = "1318437972"
Dim var2 As String = "01CdzTgUNgxIg"
Dim MD5Time As String = MD5(var1) & var2
Dim MD5Out As String = MD5(MD5Time)
MD5Out=5750b2229f7d00f955b 235616f633 fdc
So...
PHP Hash is 06b27a58c07faee223d69ca9e4 a87163
VB Hash is 5750b2229f7d00f955b235616f 633fdc
PS - My MD5 Function is provided below
Thanks in advance
I have to get data from an external PHP site to my .net site.
The developer uses the following PHP code to get a hash:
$var1=1318437972;
$var2=01CdzTgUNgxIg;
md5(md5($var1). $var2)
Hash=06b27a58c07faee223d69
I am trying to get the same hash in vb .net but the hashes are different:
Dim var1 As String = "1318437972"
Dim var2 As String = "01CdzTgUNgxIg"
Dim MD5Time As String = MD5(var1) & var2
Dim MD5Out As String = MD5(MD5Time)
MD5Out=5750b2229f7d00f955b
So...
PHP Hash is 06b27a58c07faee223d69ca9e4
VB Hash is 5750b2229f7d00f955b235616f
PS - My MD5 Function is provided below
Thanks in advance
Private Function MD5(ByVal str As String) As String
Dim provider As MD5CryptoServiceProvider
Dim bytValue() As Byte
Dim bytHash() As Byte
Dim strOutput As String = ""
Dim i As Integer
provider = New MD5CryptoServiceProvider()
bytValue = System.Text.Encoding.UTF8.GetBytes(str)
bytHash = provider.ComputeHash(bytValue)
provider.Clear()
For i = 0 To bytHash.Length - 1
strOutput &= bytHash(i).ToString("x").PadLeft(2, "0")
Next
Return strOutput
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
kaufmed did you use:
$var1=1318437972;
$var2=01CdzTgUNgxIg;
md5(md5($var1). $var2)
$var1=1318437972;
$var2=01CdzTgUNgxIg;
md5(md5($var1). $var2)
This is my PHP test:
<?php
$var1="1318437972";
$var2="01CdzTgUNgxIg";
print_r(md5(md5($var1). $var2));
?>
The PHP in the original post will throw a parse error because the $var2 value is a string, but it is not quoted. I tried it like this code snippet.
http://www.laprbass.com/RAY_temp_doctor069.php
outputs
5750b2229f7d00f955b235616f 633fdc
http://www.laprbass.com/RAY_temp_doctor069.php
outputs
5750b2229f7d00f955b235616f
<?php // RAY_temp_doctor069.php
error_reporting(E_ALL);
echo "<pre>";
// FROM THE POST AT EE, MODIFIED TO USE A STRING VARIABLE FOR $var2
$var1 = 1318437972;
$var2 = '01CdzTgUNgxIg';
$thing = md5(md5($var1). $var2);
echo $thing;
ASKER
Turns out the programmer on the other end had a typo in his string and my code was good after all!
Thanks for you help!
Thanks for you help!
ASKER
The does shed some light. Maybe the hash code is messed up on the other end!