【问题标题】:Signing POST form in C# for uploading to Amazon S3在 C# 中签署 POST 表单以上传到 Amazon S3
【发布时间】:2011-08-09 16:37:07
【问题描述】:

我在签署我的 Amazon S3 政策文件时遇到问题。

有一些关于如何在 Ruby、Java 和 Python 中执行此操作的示例,但是当我尝试在 C# 中执行此操作时,它不起作用。我不断收到一个无效的签名,我不确定我哪里出错了。 http://aws.amazon.com/articles/1434

除了 C# 之外,任何人都可以提供类似文章中的示例吗?

谢谢。

【问题讨论】:

    标签: c# amazon-s3


    【解决方案1】:

    为遇到同样问题的其他人解决了这个问题。

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

    【讨论】:

      猜你喜欢
      • 2013-01-28
      • 1970-01-01
      • 2010-12-17
      • 2013-08-30
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 2012-01-14
      • 1970-01-01
      相关资源
      最近更新 更多