mfn/aws-post-v4-sign

此包已被废弃且不再维护。作者建议使用aws/aws-sdk-php包。

为Amazon S3 POST API请求创建签名

0.1 2016-01-29 18:15 UTC

This package is auto-updated.

Last update: 2020-12-11 06:17:59 UTC


README

请使用官方AWS SDK PHP的https://github.com/aws/aws-sdk-php功能。

具体来说,请参阅https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-presigned-post.html

为AWS S3 REST API POST请求创建V4签名 Travis Build Status

主页: https://github.com/mfn/php-aws-post-v4-sign

简介

此库可以为Amazon Simple Storage (S3) REST API服务的POST请求创建签名。

此包不依赖于AWS PHP SDK。它只能创建签名。从逻辑上讲,此代码以类似的形式存在于SDK内部,但从外部无法利用它。

更多信息请参阅

需求

PHP 5.4

安装/设置

使用composer: composer.phar require mfn/aws-post-v4-sign 0.1

示例

<?php
use Mfn\Aws\Signature\V4\SignatureV4;

$secret = 'ADFSDFDS3432S23423'; # Your secret key => never share!
$time = time();
$credential = join('/', [
    $accesKeyId, # Your AWS access key ID
    gmdate('Ymd', $time),
    'us-west-1',
    's3',
    'aws4_request',
]);
# Example policy
$policy = [
    'expiration' => gmdate('Y-m-d\TH:i:s\Z', strtotime('+2 hours', $time)),
    'conditions' => [
        ['acl' => 'public-read'],
        ['bucket' => 'your-bucket'],
        ['starts-with', '$key', ''],
        ['x-amz-credential' => $credential],
        ['x-amz-algorithm' => 'AWS4-HMAC-SHA256'],
        ['x-amz-date' => gmdate('Ymd\THis\Z', $time)],
    ],
];

$sigGen = new SignatureV4(
    $secret, # the secret part; never share with anyone!
    $policy
);
$signature = $sigGen->getSignature();

SignatureV4类将解析$policy,提取x-awz-credential键,因为这个凭证是创建签名的基本部分。

为了创建签名和最终请求通常需要,需要以base64编码的JSON表示形式获取$policy,存在一个获取它的方法:$encodedPolicy = $sigGen->getBase64EncodedPolicy();

贡献

分叉它,在功能分支上修改,创建一个pull request,成为优秀开发者!

没有开发者是孤岛,所以请遵循这些标准

© Markus Fischer markus@fischer.name