Click here to Skip to main content
15,940,246 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
C#
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;
    }
Posted

1 solution

Removing \r was the solution

s = s.Replace("\r", "");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900