字符串我尝试使用哈希SHA256一个字符串,我使用下面的代码:散列与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验证码给显著不同的结果,以及在线发电机(如This generator)
有谁知道错误是什么?不同的基地?
题外话,但请记住,创建一个StringBuilder并在foreach循环使用AppendFormat代替的String.Format会防止你的代码不必要地创建大量的字符串对象。 –