12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace TencentCloud\Common;
- use TencentCloud\Common\Exception\TencentCloudSDKException;
- class Sign
- {
-
- public static function sign($secretKey, $signStr, $signMethod)
- {
- $signMethodMap = ["HmacSHA1" => "SHA1", "HmacSHA256" => "SHA256"];
- if (!array_key_exists($signMethod, $signMethodMap)) {
- throw new TencentCloudSDKException("signMethod invalid", "signMethod only support (HmacSHA1, HmacSHA256)");
- }
- $signature = base64_encode(hash_hmac($signMethodMap[$signMethod], $signStr, $secretKey, true));
- return $signature;
- }
- public static function signTC3($skey, $date, $service, $str2sign)
- {
- $dateKey = hash_hmac("SHA256", $date, "TC3".$skey, true);
- $serviceKey = hash_hmac("SHA256", $service, $dateKey, true);
- $reqKey = hash_hmac("SHA256", "tc3_request", $serviceKey, true);
- return hash_hmac("SHA256", $str2sign, $reqKey);
- }
- }
|