Create request signature

@param HttpRequest $request
@param string      $username
@param string      $timestamp
@param string      $secretKey

@return string
425106
protected function signRequest(HttpRequest $request, $username, $timestamp, $secretKey)
    {
        $message = $username
                 . $timestamp
                 . $this->getRequestMessage($request)
        ;

        return $this->algorithm->sign($message, $secretKey);
    }
585050
public function signature ( $request, $base_string, $consumer_secret, $token_secret )
	{
		// Fetch the private key cert based on the request
		$cert = $this->fetch_private_cert($request);
		
		// Pull the private key ID from the certificate
		$privatekeyid = openssl_get_privatekey($cert);
		
		// Sign using the key
		$sig = false;
		$ok  = openssl_sign($base_string, $sig, $privatekeyid);   
		
		// Release the key resource
		openssl_free_key($privatekeyid);
		  
		return $request->urlencode(base64_encode($sig));
	}
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);
    }
351439
public static function sign(RequestInterface $request, Credentials $credentials)
    {
        /**
         * @var RequestInterface $request
         */

        $signatureHeaders   = [];
        $base64Md5          = '';
        $contentLength      = '';

        if ($request->getBody()->getSize() !== 0) {
            $base64Md5 = Hmac::md5HashBase64(
                $request->getBody()
                    ->getContents()
            );

            $contentLength = strlen((string)$request->getBody());
            $signatureHeaders = array_merge(
                $signatureHeaders,
                [
                    'content-type'      => $request->getHeader('content-type'),
                    'content-md5'       => $base64Md5,
                    'content-length'    => $contentLength
                ]);
        }

        $parsedUrl = parse_url($request->getUri());
        $targetUrl = $parsedUrl["path"];
        if (!empty($parsedUrl["query"])) {
            $targetUrl = $targetUrl . "?" . $parsedUrl["query"];
        }

        $requestLine = $request->getMethod() . " " . $targetUrl . " HTTP/1.1";

        $signatureHeaders['date'] = $date = gmdate("D, d M Y H:i:s", time()) . " GMT";
        $signatureHeaders['request-line'] = $requestLine;

        $headersString      = Hmac::getHeadersString($signatureHeaders);
        $signatureString    = Hmac::getSignatureString($signatureHeaders);
        $signatureHash      = Hmac::shaHashBase64($signatureString, $credentials->getSecret());
        $authHeader         = sprintf(
            'hmac username="%s", algorithm="hmac-%s", headers="%s", signature="%s"',
            $credentials->getAccessKey(),
            Hmac::ALGORITHM_SHA256,
            $headersString,
            $signatureHash
        );

        $request = $request->withHeader('Authorization', $authHeader)
            ->withHeader('Date', $date);

        if ($request->getBody()->getSize()) {
            return $request->withHeader('Content-Type', $request->getHeader('content-type'))
                ->withHeader('Content-MD5', $base64Md5)
                ->withHeader('Content-Length', $contentLength);
        }

        return $request;
    }
1070706
def fost_hmac_request_signature_with_headers(
    secret, method, path, timestamp, headers, body):
    
    document = "%s %s\n%s\n%s\n%s" % (
        method, path,
        timestamp,
        '\n'.join(headers),
        body)
    signature = sha1_hmac(secret, document)
    logging.info("Calculated signature %s for document\n%s", signature, document)
    return document, signature
522157
function createSigningRequest($url, $keyPath, $csrPath, $confPath)
    {
        $this->cli->runAsUser(sprintf(
            'openssl req -new -key "%s" -out "%s" -subj "/C=/ST=/O=/localityName=/commonName=%s/organizationalUnitName=/emailAddress=%s%s/" -config "%s"',
            $keyPath, $csrPath, $url, $url, '@laravel.valet', $confPath
        ));
    }
1091640
public function getSignature(RequestInterface $request, $timestamp, $nonce)
    {
        $string = $this->getStringToSign($request, $timestamp, $nonce);
        $key = urlencode($this->config['consumer_secret']) . '&' . urlencode($this->config['token_secret']);

        return base64_encode(call_user_func($this->config['signature_callback'], $string, $key));
    }
415984
protected function createAuthCode($userkey, $applicationkey) {
        $payload = $userkey . "@" . strtolower($this->serverhostname) . "|" . strtolower($applicationkey);
        return strtoupper(sha1($payload));
    }
382228
private function createSignature($secret, $params)
    {
        $tokenData = $this->base64UriEncode(json_encode($params));

        $hash = $this->hash($secret.$tokenData);

        return $hash.'.'.$tokenData;
    }
427875
def api_key_get(params, request_path, _async=False):
    
    method = 'GET'
    timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
    params.update({
        'AccessKeyId': ACCESS_KEY,
        'SignatureMethod': 'HmacSHA256',
        'SignatureVersion': '2',
        'Timestamp': timestamp
    })

    host_url = TRADE_URL
    host_name = urllib.parse.urlparse(host_url).hostname
    host_name = host_name.lower()
    secret_sign = createSign(params, method, host_name, request_path,
                                     SECRET_KEY)
    params['Signature'] = secret_sign
    if PRIVATE_KEY:
        params['PrivateSignature'] = createPrivateSign(secret_sign, PRIVATE_KEY)
    url = host_url + request_path
    return http_get_request(url, params, _async=_async)
634644
public function verifySignature($uri, $secret, $paramName)
    {
        $getParams = array();
        parse_str(parse_url($uri, PHP_URL_QUERY), $getParams);

        if (!isset($getParams[$paramName])) {
            return false;
        }

        // Explode hash and data from eachother
        $parts = explode('.', $getParams[$paramName]);

        $data = array_pop($parts);

        // Decode the data
        $data = json_decode($this->base64UriDecode($data));

        // Create a new signature based on the secret and data and compare it to the data
        // we're verifying, if it is correct, return the signed data.
        if ($this->createSignature($secret, $data) === $getParams[$paramName]) {
            return $data;
        }

        return false;
    }
782493
def fost_hmac_request_signature(
    secret, method, path, timestamp, headers = {}, body = ''):
    
    signed_headers, header_values = 'X-FOST-Headers', []
    for header, value in headers.items():
        signed_headers += ' ' + header
        header_values.append(value)
    return fost_hmac_request_signature_with_headers(
        secret, method, path, timestamp,
        [signed_headers] + header_values, body)
976406
public static function generateImageSecretSignature($host, $uri, $key, $secret)
    {
        $host = strtolower($host);
        $key = (string) $key;

        $base = [];

        $magicsLength = sizeof(self::$imageUrlSecretMagics);
        $additional = [$host, $uri, $secret, $key];
        $offset = 0;
        foreach (str_split($key) as $number) {
            $offset += $number;
            $magic = self::$imageUrlSecretMagics[$offset % $magicsLength];
            $base[] = $magic;
            $base[] = array_pop($additional);
            $offset += ord($magic[0]);
            $base[] = sha1($offset, true);
            if (!$additional) {
                break;
            }
        }
        $base = join(chr($offset & 0xff), $base);
        $sha1 = str_split(sha1($base, true));
        $base = [];
        for ($i = 0; $i < 24; $i++) {
            $base[] = $sha1[($i + $offset)%sizeof($sha1)];
        }
        $base = join('', $base);
        
        return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($base))
                . substr($key, -2);
    }
515847
public static function generateImageTokenSecretSignature($host, $uri, $token, $secret)
    {
        $host = strtolower($host);

        $base = [];

        $magicsLength = sizeof(self::$imageUrlTokenMagics);
        $additional = [$host, $uri, $secret, $token];
        $offset = 0;
        foreach (str_split($token) as $number) {
            $offset += ord($number);
            $magic = self::$imageUrlTokenMagics[$offset % $magicsLength];
            $base[] = $magic;
            $base[] = array_pop($additional);
            $offset += ord($magic[0]);
            $base[] = sha1($offset, true);
            if (!$additional) {
                break;
            }
        }
        $base = join(chr($offset & 0xff), $base);
        $sha1 = str_split(sha1($base, true));
        $base = [];
        for ($i = 0; $i < 24; $i++) {
            $base[] = $sha1[($i + $offset)%sizeof($sha1)];
        }
        $base = join('', $base);
        return str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($base));
    }
293659
private function getAuthenticationHeaders(HttpRequest $request) {
		$timestamp = time();
		$version = '1';
		$path = $request->getPath();
		$securedData = $version . '|' . $this->userId . '|' . $timestamp . '|' . $request->getMethod() . '|' . $path;

		$headers = array();
		$headers['x-mac-version'] = $version;
		$headers['x-mac-userid'] = $this->userId;
		$headers['x-mac-timestamp'] = $timestamp;
		$headers['x-mac-value'] = $this->calculateHmac($securedData);
		return $headers;
	}
490526
public static function create($userId, string $secret, int $expiration, string $issuer): string
    {
        $builder = self::builder();

        return $builder->setPayloadClaim('user_id', $userId)
            ->setSecret($secret)
            ->setExpiration($expiration)
            ->setIssuer($issuer)
            ->setIssuedAt(time())
            ->build()
            ->getToken();
    }
1352608
public static HttpUrl presignV4(Request request, String region, String accessKey, String secretKey, int expires)
    throws NoSuchAlgorithmException, InvalidKeyException {
    String contentSha256 = "UNSIGNED-PAYLOAD";
    DateTime date = DateFormat.AMZ_DATE_FORMAT.parseDateTime(request.header("x-amz-date"));

    Signer signer = new Signer(request, contentSha256, date, region, accessKey, secretKey, null);
    signer.setScope();
    signer.setPresignCanonicalRequest(expires);
    signer.setStringToSign();
    signer.setSigningKey();
    signer.setSignature();

    return signer.url.newBuilder()
        .addEncodedQueryParameter(S3Escaper.encode("X-Amz-Signature"), S3Escaper.encode(signer.signature))
        .build();
  }