Skip to content

Instantly share code, notes, and snippets.

@AlexCuse
Created April 25, 2012 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCuse/2491818 to your computer and use it in GitHub Desktop.
Save AlexCuse/2491818 to your computer and use it in GitHub Desktop.
Build Authorization Key for AWS Requests in C#
/// <summary>
/// generates key to include in the "Authorization" request header
/// </summary>
/// <param name="accessKey">AWS access key</param>
/// <param name="secretKey">AWS secret key</param>
/// <param name="dateString">string included in the "x-amz-date" request header</param>
/// <returns>string to be used for signing request</returns>
static string BuildSignature(string accessKey, string secretKey, string dateString) {
var hmacSha1 = new HMACSHA1(Encoding.UTF8.GetBytes(secretKey));
var hashedDate = Convert.ToBase64String(hmacSha1.ComputeHash(Encoding.UTF8.GetBytes(dateString)));
return string.Format("AWS {0}:{1}", accessKey, hashedDate);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment