PHP code example of mfn / aws-post-v4-sign

1. Go to this page and download the library: Download mfn/aws-post-v4-sign library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mfn / aws-post-v4-sign example snippets



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