【问题标题】:All of a sudden, my Amazon S3 HTTP requests aren't working. Signature Does Not Match error. Help?突然之间,我的 Amazon S3 HTTP 请求无法正常工作。签名不匹配错误。帮助?
【发布时间】:2009-09-02 03:26:39
【问题描述】:

几天前我的代码运行良好。然后,突然间,BAM:它停止工作了。我的 PUT 停止通过,出现 SignatureDoesNotMatch 错误。帮忙?

require_once 'Crypt/HMAC.php';
require_once 'HTTP/Request.php';


function uploadFile($path_to_file, $store_file_as, $bucket, $debugmode = false) {

        $S3_URL = "http://s3.amazonaws.com/";
        $filePath = $path_to_file;
        $contentType = 'audio/mpeg';
        $keyId = 'THISISMYKEY, YES I DOUBLE CHECKED IT';
        $secretKey = 'THIS IS MYSECRET, YES I DOUBLED CHECKED IT';
        $key = $store_file_as;
        $resource = $bucket . "/" . $key;
        $acl = "public-read";
        $verb = "PUT";
    $httpDate = gmdate("D, d M Y H:i:s T");
    $stringToSign = "PUT\n\naudio/mpeg\n$httpDate\nx-amz-acl:$acl\n/$resource";
    $hasher =& new Crypt_HMAC($secretKey, "sha1");
    $str =  $hasher->hash($stringToSign);
    $raw = '';
    for ($i=0; $i < strlen($str); $i+=2) {
        $raw .= chr(hexdec(substr($str, $i, 2)));
    }
    $signature = base64_encode($raw);

    $req =& new HTTP_Request($S3_URL . $resource);
    $req->setMethod('PUT');
    $req->addHeader("content-type", $contentType);
    $req->addHeader("Date", $httpDate);
    $req->addHeader("x-amz-acl", $acl);
    $req->addHeader("Authorization", "AWS " . $keyId . ":" . $signature);
    $req->setBody(file_get_contents($filePath));  
    $req->sendRequest();
   echo $req->getResponseBody();
   }

【问题讨论】:

    标签: php amazon-s3 amazon


    【解决方案1】:

    Amazon S3 JavaScript signature tester 上运行您的签名。

    如果两个签名不匹配,您就知道密钥或签名过程有问题。

    如果两者匹配,则您的密钥和签名过程是正确的,问题出在其他地方。

    JS 测试器对于解决签名生成问题非常宝贵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-11
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2011-05-07
      • 2014-11-15
      • 1970-01-01
      • 2023-03-29
      相关资源
      最近更新 更多