Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

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=06b27a58c07faee223d69ca9e4a87163

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=5750b2229f7d00f955b235616f633fdc

So...
PHP Hash is 06b27a58c07faee223d69ca9e4a87163
VB Hash is 5750b2229f7d00f955b235616f633fdc

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

Open in new window

0
doctor069
Asked:
doctor069
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
Interesting. I ran your code as is and I received matching results:
Untitled.png
0
 
doctor069Author Commented:
Hi-

The does shed some light. Maybe the hash code is messed up on the other end!
0
 
doctor069Author Commented:
kaufmed did you use:

$var1=1318437972;
$var2=01CdzTgUNgxIg;
md5(md5($var1). $var2)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
This is my PHP test:
<?php
	$var1="1318437972";
	$var2="01CdzTgUNgxIg";

	print_r(md5(md5($var1). $var2));

?>

Open in new window

0
 
Ray PaseurCommented:
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
5750b2229f7d00f955b235616f633fdc
<?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;

Open in new window

0
 
doctor069Author Commented:
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!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now