我尝试使用SHA256哈希一个字符串,我正在使用以下代码:
using System;
using System.Security.Cryptography;
using System.Text;
public class Hash
{
public static string getHashSha256(string text)
{
byte[] bytes = Encoding.Unicode.GetBytes(text);
SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
string hashString = string.Empty;
foreach (byte x in hash)
{
hashString += String.Format("{0:x2}", x);
}
return hashString;
}
}
然而,与我的朋友的PHP以及在线生成器(例如此生成器)相比,这段代码给出了显著不同的结果。
有人知道是什么错误吗?是不同的基数吗?