在C#上传到Amazon S3签名POST表单 [英] Signing POST form in C# for uploading to Amazon S3

查看:247
本文介绍了在C#上传到Amazon S3签名POST表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法登录我的政策文件为亚马逊S3。

I am having trouble signing my policy documents for the Amazon S3.

有关于如何做到这一点的红宝石,Java和Python的例子,但是当我尝试这样做在C#中,它不工作了。我不断收到一个无效的签名,我不知道我要去哪里错了。 http://aws.amazon.com/articles/1434

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

任何人都可以提供一个例子像那些在文章中,除了C#?

Can anyone provide an example like those in the article, except for C#?

感谢。

推荐答案

解决了为别人谁运行到同样的问题。

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();
    }
}

这篇关于在C#上传到Amazon S3签名POST表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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