Converting C# Sha1 hash to PHP

时间:2015-09-01 21:53:37

标签: c# php sha1

I'm trying to get a C# Sha1 hash in PHP. The C# code was handed to me, it appears to use ASCIIEncoding which from what I read is what PHP uses. Not sure what is wrong. Any tips are appreciated.

C# code:

byte[] data = Encoding.ASCII.GetBytes(text);
byte[] HashValue; 
SHA1Managed SHhash = new SHA1Managed();
hashValue = SHhash.ComputeHash(data);
foreach (byte b in hashValue)
{
    sha1string += String.Format("{0:x2}", b);
}
return sha1string;

PHP Code:

return sha1(text);

The output:

C#  : 5f10f7410406cdab11f3c44fe8c634718eb68e98
PHP : bba18b9b35c440c25b8dcf2efb973d86ee1442e2

0 个答案:

没有答案