123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- class AWSOAuth {
- private static $SECRET_KEY = "+vB6pF3kIVHOljYeUnjIpziVHcJxy7F9j+fW3eWH";
- private static $ACCESS_KEY = "AKIAJHK7XI7GFCS24S2Q";
- private STATIC $MINUTES_EXPIRES = 5;
- private function lazySignature($key, $data) {
- if (strlen($key) > 64) {
- $key = pack('H*', sha1($key));
- }
- $key = str_pad($key, 64, chr(0x00));
- $ipad = str_repeat(chr(0x36), 64);
- $opad = str_repeat(chr(0x5c), 64);
- $hmac = pack( 'H*', sha1(
- ($key ^ $opad) . pack( 'H*', sha1(
- ($key ^ $ipad) . $data
- ))
- ));
- return base64_encode($hmac);
- }
- public function getFileSecureParams($bucket, $fileName) {
- $expires = time() + intval(floatval(AWSOAuth::$MINUTES_EXPIRES) * 60);
- $fileName = str_replace('%2F', '/', rawurlencode($fileName = ltrim($fileName, '/')));
- $signpath = '/'. $bucket .'/'. $fileName;
- $signsz = implode("\n", $pieces = array('GET', null, null, $expires, $signpath));
- $signature = $this->lazySignature(AWSOAuth::$SECRET_KEY, $signsz);
- $qs = http_build_query($pieces = array(
- 'AWSAccessKeyId' => AWSOAuth::$ACCESS_KEY,
- 'Expires' => $expires,
- 'Signature' => $signature,
- ));
- return $qs;
- }
- }
|