2

I am following the official Amazon S3 REST API documentation here and am having problems computing the same authorization values they show in their examples. The base64 HMAC-SHA1 hash they show for the first example is:

xXjDGYUmKxnwqr5KXNPGldn5LbA=

But I keep coming up with:

bWq2s1WEIj+Ydj0vQ697zp+IXMU=

I am tearing my hair out here. What can I possibly be doing wrong?

From their very first example:

static string TestS3(string key, string request) 
{
  var hash = new HMACSHA1(Encoding.UTF8.GetBytes(key));
  var data = hash.ComputeHash(Encoding.UTF8.GetBytes(request));
  return Convert.ToBase64String(data);
}

static void Main(string[] args)
{
  string key = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
  string request = "GET\n\n\nTue, 27 Mar 2007 19:36:42 +0000\n/johnsmith/photos/puppy.jpg";         
  Console.Write(TestS3(key, request));
}
Steffen Opel
  • 63,899
  • 11
  • 192
  • 211
sysrpl
  • 1,559
  • 3
  • 15
  • 24
  • [HmacSHA1 generates different signatures on different systems using same secret](http://stackoverflow.com/questions/6388737/hmacsha1-generates-different-signatures-on-different-systems-using-same-secret), maybe? – Joshua Drake May 17 '12 at 15:17
  • According to [C# in Depth - Strings in C# and .NET](http://csharpindepth.com/Articles/General/Strings.aspx), linked from [Determine a string's encoding in C#](http://stackoverflow.com/questions/1025332/determine-a-strings-encoding-in-c-sharp), .NET strings are UTF-16. – Joshua Drake May 17 '12 at 15:29

1 Answers1

0

Okay I found the problem. The keys used in the examples are wrong.

sysrpl
  • 1,559
  • 3
  • 15
  • 24