c#SHA-256哈希为亚马逊弹性转码器 [英] c# SHA-256 Hashing for amazon elastic transcoder

查看:135
本文介绍了c#SHA-256哈希为亚马逊弹性转码器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用亚马逊的弹性转码器。这里我需要sha-256哈希一个字符串;

http://docs.aws。 amazon.com/general/latest/gr/sigv4-create-canonical-request.html



我尝试过网上找到的任何方式但我找不到与页面相同的结果和一些在线哈希站点提供的结果。



这是哈希的字符串,您可以从上面的链接中找到;



POST

/



content-type:application /的X WWW窗体-urlencoded; charset = utf-8

主持人:iam.amazonaws.com

x-amz-date:20110909T233600Z



content-type; host; x-amz-date

b6359072c78d70ebee1e81adcbab4f01bf2c23245fa365ef83fe8f1f955085e2





这里是预期的结果:



3511de7e95d28ecd39e9513b642aee07e54f4941150d8df8bf94b328ef7e55e2



我尝试了很多c#方法但无法得到这个结果;但这些在线网站提供相同的结果;



http://crypo.in.ua/tools/eng_sha256.php



这是我的方法之一;

I'm trying to use elastic transcoder of Amazon. Here I need to sha-256 hash a string;
http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html

I have tried any ways I have found on the net but I couldn't find the same result as page and some online hashing sites provides.

Here is the string to hash which you can find from the link above;

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


Here is the expected result:

3511de7e95d28ecd39e9513b642aee07e54f4941150d8df8bf94b328ef7e55e2

I have tried many c# method but couldn't get this result; but these online sites provides same results;

http://crypo.in.ua/tools/eng_sha256.php

Here is one of my method;

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,);
Removing \r was the solution

s = s.Replace("\r", "");


这篇关于c#SHA-256哈希为亚马逊弹性转码器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆