Here is the code of .net
public string GetMD5Hash(string name) {
MD5 md5 = new MD5CryptoServiceProvider();
byte[] ba = md5.ComputeHash(Encoding.UTF8.GetBytes(name));
StringBuilder hex = new StringBuilder(ba.Length * 2);
foreach (byte b in ba)
hex.AppendFormat("{0:x2}", b);
return Convert.ToString(hex);
}
and in the php I am using the below code
class foobar {
public function str2hex($string) {
$hex = "";
for ($i = 0; $i < strlen($string); $i++)
$hex .= (strlen(dechex(ord($string[$i]))) < 2) ? "0" . dechex(ord($string[$i])) : dechex(ord($string[$i]));
return $hex;
}
public function GetMD5($pStr) {
$data = mb_convert_encoding($pStr, 'UTF-16LE', 'UTF-8');
$h = $this->str2hex(md5($data, true));
return $h;
}
}
$foobar = new foobar;
$nisha =$foobar->GetMD5('5698882');
echo "</br>";
echo $nisha;
but the output is not matching with the .net encryption output both are different
To generate
md5
hash of a string in php, you simply need to use themd5()
function more details at http://php.net/manual/en/function.md5.phpYou can use these codes to get md5 hash which will be same for both .net and php
PHP md5 hash
.NET md5 hash