【发布时间】:2014-02-22 06:44:52
【问题描述】:
遇到问题了——也许……看来这一段PHP:
$mydigestb = hash("sha256",$digeststring);
不会生成与此 C# 代码相同的结果:
private string GenerateDigest(long currentTime)
{
SHA256Managed hashString = new SHA256Managed();
StringBuilder hex = new StringBuilder();
byte[] hashValue = hashString.ComputeHash(Encoding.UTF8.GetBytes(String.Format("{0}{1}", currentTime, txtApiKey.Text)));
foreach (byte x in hashValue)
{
hex.AppendFormat("{0:x2}", x);
}
return hex.ToString();
}
输入的值是一样的,但是出来的好像不一样。
【问题讨论】:
-
它们对我来说是一样的。显示您正在测试它的确切值。也许是字符编码差异?