Skip to content

Commit

Permalink
Fix auth problem (#20)
Browse files Browse the repository at this point in the history
* Fix Auth

* Fix Auth

* release 4.3.4
  • Loading branch information
lewzylu authored Aug 21, 2017
1 parent a3d951a commit 1b1e739
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/qcloud/cos/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Api {
//版本
const VERSION = 'v4.3.2';
const VERSION = 'v4.3.4';
//计算sign签名的时间参数
const EXPIRED_SECONDS = 180;
//1M
Expand Down
9 changes: 7 additions & 2 deletions src/qcloud/cos/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function createReusableSignature($expiration, $bucket, $filepath = null)
$filepath = '/' . $filepath;
}

return $this->createSignature($appId, $secretId, $secretKey, $expiration, $bucket, $filepath);
$fileId = '/' . $appId . '/' . $bucket . $filepath;
return $this->createSignature($appId, $secretId, $secretKey, $expiration, $bucket, $fileId);
}
}

Expand Down Expand Up @@ -84,12 +85,16 @@ private function createSignature(

$now = time();
$random = rand();
$plainText = "a=$appId&k=$secretId&e=$expiration&t=$now&r=$random&f=$fileId&b=$bucket";
$fileId = $this->encodeKey($fileId);
$plainText = "a=$appId&b=$bucket&k=$secretId&e=$expiration&t=$now&r=$random&f=$fileId";
$bin = hash_hmac('SHA1', $plainText, $secretKey, true);
$bin = $bin.$plainText;

$signature = base64_encode($bin);

return $signature;
}
public static function encodeKey($key) {
return str_replace('%2F', '/', rawurlencode($key));
}
}

0 comments on commit 1b1e739

Please sign in to comment.