$value) { $canonicalized .= '&' . self::percentEncode($key) . '=' . self::percentEncode($value); } return $method . '&%2F&' . self::percentEncode(substr($canonicalized, 1)); } /** * @param string $string * @param string $accessKeySecret * * @return string */ public static function shaHmac1sign($string, $accessKeySecret) { return base64_encode(hash_hmac('sha1', $string, $accessKeySecret, true)); } /** * @param string $string * @param string $accessKeySecret * * @return string */ public static function shaHmac256sign($string, $accessKeySecret) { return base64_encode(hash_hmac('sha256', $string, $accessKeySecret, true)); } /** * @param string $string * @param string $privateKey * * @return string */ public static function shaHmac256WithRsasign($string, $privateKey) { $binarySignature = ''; try { openssl_sign( $string, $binarySignature, $privateKey, \OPENSSL_ALGO_SHA256 ); } catch (Exception $exception) { throw new InvalidArgumentException( $exception->getMessage() ); } return base64_encode($binarySignature); } /** * @param string $string * * @return null|string|string[] */ private static function percentEncode($string) { $result = rawurlencode($string); $result = str_replace(['+', '*'], ['%20', '%2A'], $result); $result = preg_replace('/%7E/', '~', $result); return $result; } /** * @return Client * @throws Exception */ public static function createClient() { if (Credentials::hasMock()) { $stack = HandlerStack::create(Credentials::getMock()); $history = Credentials::getHandlerHistory(); $stack->push($history); } else { $stack = HandlerStack::create(); } $stack->push(Middleware::mapResponse(static function (ResponseInterface $response) { return new Response($response); })); self::$config['handler'] = $stack; return new Client(self::$config); } }