c# SHA-256 Hash
本文关键字:Hash SHA-256 | 更新日期: 2023-09-27 18:04:30
我正在尝试使用亚马逊的弹性转码器。这里我需要对字符串进行sha-256哈希;http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
我已经尝试了我在网上找到的任何方法,但我找不到与页面和一些在线哈希网站提供的相同的结果。
这是要散列的字符串,您可以从上面的链接中找到;
POST
/
content-type:application/x-www-form-urlencoded; charset=utf-8
host:iam.amazonaws.com
x-amz-date:20110909T233600Z
content-type;host;x-amz-date
b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f955085e2
下面是预期的结果:
3511 de7e95d28ecd39e9513b642aee07e54f4941150d8df8bf94b328ef7e55e2
我已经尝试了许多c#方法,但无法得到这个结果;但是这些网站提供的结果是一样的;
http://crypo.in.ua/tools/eng_sha256.php这是我的一个方法;
public static string getHashSha256(string text)
{
byte[] bytes = Encoding.UTF8.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;
}
删除'r是解决方案s = s. replace ("'r", ");