Generate a signature from the request.

@throws \Acquia\Hmac\Exception\MalformedRequestException
When a required header is missing.

@return string
The generated signature.
329338
protected function generateSignature()
    {
        if (!$this->request->hasHeader('X-Authorization-Timestamp')) {
            throw new MalformedRequestException(
                'X-Authorization-Timestamp header missing from request.',
                null,
                0,
                $this->request
            );
        }

        $host = $this->request->getUri()->getHost();
        $port = $this->request->getUri()->getPort();

        if ($port) {
            $host .= ':' . $port;
        }

        $parts = [
            strtoupper($this->request->getMethod()),
            $host,
            $this->request->getUri()->getPath(),
            $this->request->getUri()->getQuery(),
            $this->serializeAuthorizationParameters(),
        ];

        $parts = array_merge($parts, $this->normalizeCustomHeaders());

        $parts[] = $this->request->getHeaderLine('X-Authorization-Timestamp');

        $body = (string) $this->request->getBody();

        if (strlen($body)) {
            if ($this->request->hasHeader('Content-Type')) {
                $parts[] = $this->request->getHeaderLine('Content-Type');
            }

            $parts[] = $this->digest->hash((string) $body);
        }

        return $this->digest->sign(implode("\n", $parts), $this->key->getSecret());
    }
181322
protected function findHeader(array $headers): string
    {
        $signature = '';
        foreach ($headers as $header) {
            if ($this->request->hasHeader($header)) {
                $value = $this->request->getHeader($header);
                $value = array_shift($value);
                if ($value !== null) {
                    $signature = $value;
                    continue;
                }
            }
        }

        return $signature;
    }
949368
private function generateSignature(DOMElement $signedInfoNode)
    {
        $signature = null;

        if (!openssl_sign(
            $signedInfoNode->C14N(true),
            $signature,
            $this->getPrivateKeyResource(),
            OPENSSL_ALGO_SHA1
        )
        ) {
            throw new \Exception('Unable to sign the request');
        }

        return $signature;
    }
30749
protected function getAuthHeader()
    {
        if ($this->apiClient->accessToken && $this->apiClient->accessToken->isValid) {
            return 'Authorization: OAuth ' . $this->apiClient->accessToken->token;
        }
        throw new InvalidParamException('NOT VALID ACCESS TOKEN', self::CODE_UNAUTHORIZED);
    }
648417
private function buildHeader(){

        $formClass = $this->getClassName('str');
        $formName = $this->formName;
        $formNs = $this->formNs;

        $action = $this->action;
        $method = $this->method;
        $enctype = $this->enctype;
        $header = "<form action='".$action."' method='".$method."' class='".$formNs.$formClass."' id='".$formNs.$formName."' name='".$formNs.$formName."' enctype='".$enctype."'>";

        return $header;
    }
1169468
private function prepare_oauth_signature() {
    $this->request_settings['oauth1_params']['oauth_signature'] = $this->safe_encode(
      base64_encode(
        hash_hmac(
          'sha1', $this->request_settings['basestring'], $this->request_settings['signing_key'], true
    )));
  }
26027
private function _generateKey()
    {
        if ($this->_key == '') {
            $this->_key = pack(
                'H*',
                hash('SHA256', md5(uniqid()))
            );
        }

        return $this->_key;
    }
291059
public function getParameters()
    {
        $parameters = \array_merge($this->parameters, [
            'oauth_consumer_key'     => $this->consumerKey,
            'oauth_timestamp'        => $this->timestamp,
            'oauth_nonce'            => \sha1(\microtime()),
            'oauth_signature_method' => 'HMAC-' . self::HASH_ALGORITHM,
        ]);

        // The parameters above must be included in the signature generation.
        $parameters['oauth_signature'] = $this->generateOauthSignature($parameters);

        return $this->getSortedParameters($parameters);
    }
360126
public function generateSigninInput()
    {
        $base64payload = $this->encoder->encode(json_encode($this->getPayload(), JSON_UNESCAPED_SLASHES));
        $base64header = $this->encoder->encode(json_encode($this->getHeader(), JSON_UNESCAPED_SLASHES));

        return sprintf('%s.%s', $base64header, $base64payload);
    }
1269056
protected function encodeHeader(): string
    {
        return \pack('n*', ...[
            $this->id,
            $this->getFlags(),
            \count($this->questions),
            \count($this->answers),
            $this->authorityCount,
            $this->additionalCount
        ]);
    }
1260016
public function getSignature()
    {
        if ($this->hasFileParameters()) {
            $elements = $this->getOAuthParameters();
        } else {
            $elements = array_merge(
                $this->getOAuthParameters(),
                $this->getGetParameters(),
                $this->getPostParameters()
            );
        }

        ksort($elements);

        $stringSignature = array();
        foreach ($elements as $key => $value) {
            $stringSignature[] = sprintf('%s=%s', $key, $value);
        }

        $signature = array(
            $this->getMethod(),
            rawurlencode($this->getSignatureUrl()),
            rawurlencode(implode('&', $stringSignature)),
        );

        return implode('&', $signature);
    }
1360180
private function createSignature(RequestInterface $request)
    {
        $headers = $request->getHeaders();
        ksort($headers);

        $signatureData = $request->getMethod() . ' ' . $request->getRequestTarget();
        $signatureData .= $this->createSignatureDataFromHeaders($headers);
        $signatureData .= "\n\n";

        $body = (string)$request->getBody();
        if (!empty($body)) {
            $signatureData .= $body;
        }

        return $this->sign($signatureData);
    }
1260373
public function to_header() {/*{{{*/
    $out ='Authorization: OAuth realm=""';
    $total = array();
    foreach ($this->parameters as $k => $v) {
      if (substr($k, 0, 5) != "oauth") continue;
      if (is_array($v)) throw new OAuthException('Arrays not supported in headers');
      $out .= ',' . OAuthUtil::urlencode_rfc3986($k) . '="' . OAuthUtil::urlencode_rfc3986($v) . '"';
    }
    return $out;
  }
689905
private function createHeader()
    {
        $headers = $this->headers;

        $username = $this->getUsername();
        $auth_type = $this->getAuthType();

        if ('hash' == $auth_type) {
            $headers['Authorization'] = 'WHM ' . $username . ':' . preg_replace("'(\r|\n|\s|\t)'", '', $this->getPassword());
        } elseif ('password' == $auth_type) {
            $headers['Authorization'] = 'Basic ' . base64_encode($username . ':' .$this->getPassword());
        }
        return $headers;
    }
1266792
final protected function createHeader()
    {
        $host = $this->host;
        if ($host === '127.0.0.1' || $host === '0.0.0.0')
        {
            $host = 'localhost';
        }

        return "GET {$this->path} HTTP/1.1" . "\r\n" .
        "Origin: null" . "\r\n" .
        "Host: {$host}:{$this->port}" . "\r\n" .
        "Sec-WebSocket-Key: {$this->key}" . "\r\n" .
        "User-Agent: ".self::UserAgent."/" . self::VERSION . "\r\n" .
        "Upgrade: Websocket" . "\r\n" .
        "Connection: Upgrade" . "\r\n" .
        "Sec-WebSocket-Protocol: wamp" . "\r\n" .
        "Sec-WebSocket-Version: 13" . "\r\n" . "\r\n";
    }
19048
protected function generateVerifyCode()
	{
		if($this->minLength > $this->maxLength)
			$this->maxLength = $this->minLength;
		if($this->minLength < 3)
			$this->minLength = 3;
		if($this->maxLength > 20)
			$this->maxLength = 20;
		$length = mt_rand($this->minLength,$this->maxLength);

		$letters = 'bcdfghjklmnpqrstvwxyz';
		$vowels = 'aeiou';
		$code = '';
		for($i = 0; $i < $length; ++$i)
		{
			if($i % 2 && mt_rand(0,10) > 2 || !($i % 2) && mt_rand(0,10) > 9)
				$code.=$vowels[mt_rand(0,4)];
			else
				$code.=$letters[mt_rand(0,20)];
		}

		return $code;
	}
353965
function signature ( $request, $base_string, $consumer_secret, $token_secret )
	{
		$key = $request->urlencode($consumer_secret).'&'.$request->urlencode($token_secret);
		if (function_exists('hash_hmac'))
		{
			$signature = base64_encode(hash_hmac("sha1", $base_string, $key, true));
		}
		else
		{
		    $blocksize	= 64;
		    $hashfunc	= 'sha1';
		    if (strlen($key) > $blocksize)
		    {
		        $key = pack('H*', $hashfunc($key));
		    }
		    $key	= str_pad($key,$blocksize,chr(0x00));
		    $ipad	= str_repeat(chr(0x36),$blocksize);
		    $opad	= str_repeat(chr(0x5c),$blocksize);
		    $hmac 	= pack(
		                'H*',$hashfunc(
		                    ($key^$opad).pack(
		                        'H*',$hashfunc(
		                            ($key^$ipad).$base_string
		                        )
		                    )
		                )
		            );
			$signature = base64_encode($hmac);
		}
		return $request->urlencode($signature);
	}