I am having trouble signing my policy documents for the Amazon S3.
There are examples on how to do it in Ruby, Java, and Python, but when I try to do it in C#, it's not working out. I keep getting an invalid signature, and I'm not sure where I'm going wrong. http://aws.amazon.com/articles/1434
Can anyone provide an example like those in the article, except for C#?
Thanks.
Solved it for anyone else who runs into the same problem.
class Program
{
static string secretKey = "Removed";
static void Main(string[] args)
{
string policyStr = @"{""expiration"": ""2012-01-01T12:00:00.000Z"",""conditions"": [{""bucket"": ""<bucket>"" },{""acl"": ""public-read"" },[""eq"", ""$key"", ""<filename>""],[""starts-with"", ""$Content-Type"", ""image/""],]}";
GetSig(policyStr);
}
static void GetSig(string policyStr)
{
string b64Policy = Convert.ToBase64String(Encoding.ASCII.GetBytes(policyStr));
byte[] b64Key = Encoding.ASCII.GetBytes(secretKey);
HMACSHA1 hmacSha1 = new HMACSHA1(b64Key);
Console.WriteLine(policyStr);
Console.WriteLine(b64Policy);
Console.WriteLine();
Console.WriteLine(
Convert.ToBase64String(hmacSha1.ComputeHash(Encoding.ASCII.GetBytes(b64Policy))));
Console.ReadKey();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With