Add an Ed25519 signature to an HTTP request object.

@param RequestInterface $request
@param SigningSecretKey $secretKey
@return RequestInterface
9481
public function signRequest(
        RequestInterface $request,
        SigningSecretKey $secretKey
    ): RequestInterface {
        $signature = \ParagonIE_Sodium_Compat::crypto_sign_detached(
            (string) $request->getBody(),
            $secretKey->getString(true)
        );
        return $request->withAddedHeader(
            (string) static::HEADER_SIGNATURE_NAME,
            Base64UrlSafe::encode($signature)
        );
    }
456996
private function getCacheKey(ServerRequestInterface $request)
    {
        $id = base64_encode((string) $request->getUri());
        $hints = $this->getClientHints($request);

        if ($hints) {
            $id .= '.'.base64_encode(json_encode($hints));
        }

        return $id;
    }
111475
private function cacheKeyFromRequest(RequestInterface $request)
    {
        $uri = $request->getUri();

        $queryStr = $uri->getQuery();
        if (!empty($queryStr)) {
            $queryArr = [];

            parse_str($queryStr, $queryArr);

            $queryArr = $this->parseIgnoredParams($queryArr);
            $queryStr = http_build_query($queryArr);

            $uri = $uri->withQuery($queryStr);
        }

        $cacheKey = 'request/' . $request->getMethod() . '/' . md5((string)$uri);
        return $cacheKey;
    }
13159
public function signMerchantRequest($request) {
		if(!isset($this->merchant_privatekey)) {
			throw new Trustly_SignatureException('No private key has been loaded for signing');
		}

		$method = $request->getMethod();
		if($method === NULL) {
			$method = '';
		}
		$uuid = $request->getUUID();
		if($uuid === NULL) {
			$uuid = '';
		}

		$data = $request->getData();

		$serial_data = $method . $uuid . $this->serializeData($data);
		$raw_signature = '';

		$this->clearOpenSSLError();
		if(openssl_sign($serial_data, $raw_signature, $this->merchant_privatekey, OPENSSL_ALGO_SHA1) === TRUE) {
			return base64_encode($raw_signature);
		}

		throw new Trustly_SignatureException('Failed to sign the outgoing merchant request. '. openssl_error_string());
	}
271696
public static function sign($url, $secret, $clientId = null, $channel = null)
    {
        if ($clientId !== null) {
            $url .= '&client=gme-'.$clientId;
        }

        if ($channel !== null) {
            $url .= '&channel='.$channel;
        }

        $urlParts = parse_url($url);
        $data = $urlParts['path'].'?'.$urlParts['query'];
        $key = base64_decode(str_replace(['-', '_'], ['+', '/'], $secret));
        $signature = base64_encode(hash_hmac('sha1', $data, $key, true));

        return $url.'&signature='.str_replace(['+', '/'], ['-', '_'], $signature);
    }
484569
protected function setupKeyPair(EncryptionSecretKey $secret): void
    {
        $this->secretKey = $secret;
        $this->publicKey = $this->secretKey->derivePublicKey();
    }
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);
    }
1279857
private function createCacheKey(RequestInterface $request)
    {
        $key = $this->config['cache_key_generator']->generate($request);

        return hash($this->config['hash_algo'], $key);
    }
235398
public function decodeSignedJsonRequest(
        RequestInterface $request,
        SigningPublicKey $publicKey
    ): array {
        /** @var array|bool $array */
        $array = \json_decode(
            $this->verifySignedStringRequest($request, $publicKey),
            true
        );
        if (!\is_array($array)) {
            throw new InvalidMessageException('Could not decode JSON');
        }
        return $array;
    }
226609
public static function create($userIdentifier, $secretKey, $logger = null)
    {
        $client = self::initializeHttpClient(self::ENDPOINT_URL);

        return new self($userIdentifier, $secretKey, $client, $logger);
    }
370071
private function signRequest(
        RequestInterface $request,
        array $packedCommands = []
    ): RequestInterface {
        $signature = [
            $request->getMethod(),
            $request->getHeaderLine('Content-MD5'),
            $request->getHeaderLine('Content-Type'),
            $request->getHeaderLine('Date')
        ];

        $normalizedCommands = [];
        foreach ($packedCommands as $command => $value) {
            if (!empty($value)) {
                $normalizedCommands[] = strtolower($command) . ':' . $value;
            }
        }

        if (!empty($normalizedCommands)) {
            sort($normalizedCommands);
            $signature[] = join("\n", $normalizedCommands);
        }

        $signature[] = $request->getUri()->getPath();

        return $request->withAddedHeader(
            'Authorization',
            'AWS ' . $this->options['key'] . ':' . base64_encode(hash_hmac(
                'sha1',
                join("\n", $signature),
                $this->options['secret'],
                true
            ))
        );
    }
1100210
public function validate(string $secretKey): bool
    {
        $contentMD5 = $this->request->getHeader('Content-MD5');

        if ($contentMD5) {
            // We need to validate the integrity of the request
            $body = $this->request->getBody();
            $this->request->setBody($body);

            if ($contentMD5 !== base64_encode(md5((string) $body, true))) {
                // content-md5 header did not match md5 signature of body
                $this->errorCode = self::ERR_MD5CHECKSUMWRONG;

                return false;
            }
        }

        if (!$requestDate = $this->request->getHeader('x-amz-date')) {
            $requestDate = $this->request->getHeader('Date');
        }

        if (!$this->validateRFC2616Date((string) $requestDate)) {
            return false;
        }

        $amzHeaders = $this->getAmzHeaders();

        $signature = base64_encode(
            $this->hmacsha1($secretKey,
                $this->request->getMethod()."\n".
                $contentMD5."\n".
                $this->request->getHeader('Content-type')."\n".
                $requestDate."\n".
                $amzHeaders.
                $this->request->getUrl()
            )
        );

        if ($this->signature !== $signature) {
            $this->errorCode = self::ERR_INVALIDSIGNATURE;

            return false;
        }

        return true;
    }
766495
public function decryptRequestWithSharedKey(
        RequestInterface $request,
        SharedEncryptionKey $key
    ): RequestInterface {
        $encrypted = Base64UrlSafe::decode((string) $request->getBody());
        return $request->withBody(
            $this->adapter->stringToStream(
                Simple::decrypt($encrypted, $key)
            )
        );
    }
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));
	}
1190909
public function execute(RequestInterface $request): RequestInterface
    {
        $body = $request->getBody()->getContents();

        $iv = random_bytes(self::INITIATION_VECTOR_LENGTH);
        $aesKey = random_bytes(self::AES_KEY_LENGTH);
        $encryptedAesKey = $this->publicKey->encrypt($aesKey);
        $bodyEncrypted = $this->determineBodyStringEncrypted($body, $aesKey, $iv);
        $hmac = $this->determineHmac($aesKey, $iv, $bodyEncrypted);
        $encryptedHeaders = [
            self::HEADER_CLIENT_ENCRYPTION_IV => [base64_encode($iv)],
            self::HEADER_CLIENT_ENCRYPTION_KEY => [base64_encode($encryptedAesKey)],
            self::HEADER_CLIENT_ENCRYPTION_HMAC => [base64_encode($hmac)],
        ];

        return new Request(
            $request->getMethod(),
            $request->getUri(),
            array_merge($request->getHeaders(), $encryptedHeaders),
            $bodyEncrypted
        );
    }
267797
public function add(Request $request,$secret) {
        $task = $request->put();
        $task_id = $this->queueService->addTask($task);
        return ['success' => true, 'task_id' => $task_id];
    }
319284
public function doCall($serverKey, $request) {
    $client = $this->getClient($serverKey);
    if ($client) {
      $response = $client->call($request);
      return $response;
    }
    return ObjectFactory::getNewInstance('response');
  }