我正在尝试使用亚马逊的弹性转码器。 这里我需要对一个字符串进行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
这是预期的结果:
3511de7e95d28ecd39e9513b642aee07e54f4941150d8df8bf94b328ef7e55e2
我尝试了很多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", "");
关于时间:2019-03-17 标签:c#SHA-256Hash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31604699/