Generate the MAC signature

@param string $url Called URL
@param array  $parameters Parameters
@param string $http_method Http Method
@return string
353242
private function generateMACSignature($url, $parameters, $http_method)
    {
        $timestamp = time();
        $nonce = uniqid();
        $parsed_url = parse_url($url);
        if (!isset($parsed_url['port']))
        {
            $parsed_url['port'] = ($parsed_url['scheme'] == 'https') ? 443 : 80;
        }
        if ($http_method == self::HTTP_METHOD_GET) {
            if (is_array($parameters)) {
                $parsed_url['path'] .= '?' . http_build_query($parameters, null, '&');
            } elseif ($parameters) {
                $parsed_url['path'] .= '?' . $parameters;
            }
        }

        $signature = base64_encode(hash_hmac($this->access_token_algorithm,
                    $timestamp . "\n"
                    . $nonce . "\n"
                    . $http_method . "\n"
                    . $parsed_url['path'] . "\n"
                    . $parsed_url['host'] . "\n"
                    . $parsed_url['port'] . "\n\n"
                    , $this->access_token_secret, true));

        return 'id="' . $this->access_token . '", ts="' . $timestamp . '", nonce="' . $nonce . '", mac="' . $signature . '"';
    }
549973
public function generateUrl(string $name, array $parameters = []): string
    {
        $definition = $this->provider->getRouteDefinitionByName($name);
        return $definition->formatUrl($parameters);
    }
362096
def generate_oauth_signature(self, params, url):
        
        if "oauth_signature" in params.keys():
            del params["oauth_signature"]

        base_request_uri = quote(url, "")
        params = self.sorted_params(params)
        params = self.normalize_parameters(params)
        query_params = ["{param_key}%3D{param_value}".format(param_key=key, param_value=value)
                        for key, value in params.items()]

        query_string = "%26".join(query_params)
        string_to_sign = "%s&%s&%s" % (self.method, base_request_uri, query_string)

        consumer_secret = str(self.consumer_secret)
        if self.version not in ["v1", "v2"]:
            consumer_secret += "&"

        hash_signature = HMAC(
            consumer_secret.encode(),
            str(string_to_sign).encode(),
            sha256
        ).digest()

        return b64encode(hash_signature).decode("utf-8").replace("\n", "")
105457
public function signUrl($url)
    {
        if (strrpos($url, '?') === false) {
            // append ? if one doesn't exist
            $url .= '?';
        }
        return sprintf('%s&policy=%s&signature=%s',
            $url, $this->policy, $this->signature);
    }
1246687
public static function from_request($http_method=NULL, $http_url=NULL, $parameters=NULL) {
    $scheme = (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on")
              ? 'http'
              : 'https';
    $port = "";
    if ( isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != "80" && $_SERVER['SERVER_PORT'] != "443" &&
        strpos(':', $_SERVER['HTTP_HOST']) < 0 ) {
      $port =  ':' . $_SERVER['SERVER_PORT'] ;
    }
    @$http_url or $http_url = $scheme .
                              '://' . $_SERVER['HTTP_HOST'] .
                              $port .
                              $_SERVER['REQUEST_URI'];
    @$http_method or $http_method = $_SERVER['REQUEST_METHOD'];

    // We weren't handed any parameters, so let's find the ones relevant to
    // this request.
    // If you run XML-RPC or similar you should use this to provide your own
    // parsed parameter-list
    if (!$parameters) {
      // Find request headers
      $request_headers = OAuthUtil::get_headers();

      // Parse the query-string to find GET parameters
      $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);

      $ourpost = $_POST;
      // Deal with magic_quotes
      // http://www.php.net/manual/en/security.magicquotes.disabling.php
      if ( get_magic_quotes_gpc() ) {
         $ourpost = array();
         foreach ($_POST as $k => $v) {
            $v = stripslashes($v);
            $ourpost[$k] = $v;
         }
      }
     // Add POST Parameters if they exist
      $parameters = array_merge($parameters, $ourpost);

      // We have a Authorization-header with OAuth data. Parse the header
      // and add those overriding any duplicates from GET or POST
      if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
        $header_parameters = OAuthUtil::split_header(
          $request_headers['Authorization']
        );
        $parameters = array_merge($parameters, $header_parameters);
      }

    }

    return new OAuthRequest($http_method, $http_url, $parameters);
  }
1088966
public function getSignature(Url $uri, array $params, $method = 'POST')
    {
        parse_str($uri->getQuery(), $queryStringData);

        foreach (array_merge($queryStringData, $params) as $key => $value) {
            $signatureData[ rawurlencode($key) ] = rawurlencode($value);
        }

        ksort($signatureData);

        // determine base uri
        $baseUri = $uri->getScheme() . '://' . $uri->getAuthority();

        if ('/' === $uri->getPath()->getUriComponent()) {
            $baseUri .= '/';
        } else {
            $baseUri .= $uri->getPath()->getUriComponent();
        }

        $baseString = strtoupper($method) . '&';
        $baseString .= rawurlencode($baseUri) . '&';
        $baseString .= rawurlencode($this->buildSignatureDataString($signatureData));

        return base64_encode($this->hash($baseString));
    }
1154648
def createSign(pParams, method, host_url, request_path, secret_key):
    
    sorted_params = sorted(pParams.items(), key=lambda d: d[0], reverse=False)
    encode_params = urllib.parse.urlencode(sorted_params)
    payload = [method, host_url, request_path, encode_params]
    payload = '\n'.join(payload)
    payload = payload.encode(encoding='UTF8')
    secret_key = secret_key.encode(encoding='UTF8')

    digest = hmac.new(secret_key, payload, digestmod=hashlib.sha256).digest()
    signature = base64.b64encode(digest)
    signature = signature.decode()
    return signature
807166
public function generateWebhookSignature(
        string $url,
        \stdClass $data,
        string $secret_key
    ) {
        $signature = $url;
        $signature .= json_encode($data);

        return base64_encode(hash_hmac('sha1', $signature, $secret_key, true));
    }
513464
private function buildUrlWithHost($url, array $parameters)
    {
        return
            trim($this->host, '/') .
            '/' .
            ltrim(
                $this
                    ->urlGeneratorInterface
                    ->generate(
                        $url,
                        $parameters,
                        UrlGeneratorInterface::ABSOLUTE_PATH
                    ), '/'
            );
    }
333273
protected function normalizeUrl($url, array $parameters = [])
    {
        $normalizedUrl = $url;
        if (!empty($parameters)) {
            $normalizedUrl .= (false !== strpos($url, '?') ? '&' : '?').http_build_query($parameters, '', '&');
        }

        return $normalizedUrl;
    }
895347
protected function generateSign($params = [])
    {
        if ($this->sign_method == 'md5') {
            return $this->generateMd5Sign($params);
        } elseif ($this->sign_method == 'hmac') {
            return $this->generateHmacSign($params);
        } else {
            throw new Exception("sign_method错误...");
        }
    }
469150
function signature ( $request, $base_string, $consumer_secret, $token_secret )
	{
		return $request->urlencode($request->urlencode($consumer_secret).'&'.$request->urlencode($token_secret));
	}
410270
private function signature(array $payload, $method, $uri, $secret)
    {
        $payload = urldecode(http_build_query($payload));

        $payload = implode("\n", [$method, $uri, $payload]);

        return hash_hmac('sha256', $payload, $secret);
    }
834316
public function signatureA($url, $key = null, $timestamp = null, $random = null, $signName = 'sign')
    {
        $key = $key ?: $this->getConfig()->get('cdn_key');
        $timestamp = $timestamp ?: time();
        $random = $random ?: sha1(uniqid('', true));

        $parsed = parse_url($url);
        $hash = md5(sprintf('%s-%s-%s-%s-%s', $parsed['path'], $timestamp, $random, 0, $key));
        $signature = sprintf('%s-%s-%s-%s', $timestamp, $random, 0, $hash);
        $query = http_build_query([$signName => $signature]);
        $separator = empty($parsed['query']) ? '?' : '&';

        return $url.$separator.$query;
    }
126030
protected function execute($request_method, $url, $parameters = null)
	{
		$extra_options = array(
			CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
			CURLOPT_USERPWD => $this->_apiUsername . ':' . $this->_apiKey,
		);

		$url = 'https://www.browserstack.com/automate/' . $url;

		list($raw_results,) = $this->_curlService->execute($request_method, $url, $parameters, $extra_options);

		return json_decode($raw_results, true);
	}
269447
public function generate($method, $url, array $data = [], array $headers = [], $basicAuthCredentials = '')
    {
        $signatureParts = [$method, $url];
        $signatureParts[] = http_build_query($data);
        $signatureParts[] = http_build_query($headers);
        $signatureParts[] = $basicAuthCredentials;

        return implode('|', $signatureParts);
    }
150499
private function buildUrlWithoutHost($url, array $parameters)
    {
        return $this
            ->urlGeneratorInterface
            ->generate(
                $url,
                $parameters,
                UrlGeneratorInterface::ABSOLUTE_URL
            );
    }