时间:2019-03-17 标签:c#SHA-256Hash

标签 c# hash sha256

我正在尝试使用亚马逊的弹性转码器。 这里我需要对一个字符串进行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/

相关文章:

excel - 获取API数据时的"Signature not valid"(VBA-Excel)

python - 通过 Python 为自定义 MTA 生成 DKIM 签名

c# - 为什么从另一个类访问时static int总是0

c# - 将 html 转换为 MSWord

ruby - 如何比较两个哈希值?

ruby - 硬币变化递归哈希(解释)?

java - sha256 哈希函数中三个字节中的两个不同

c# - 是否可以选择 Windows 窗体标签上的文本?

c# - Mongo 和 C# 的日期时间问题

php - 如何在 Python 中获取相同的 PHP adler32 哈希?