Encrypt your HTTP request with a pre-shared key.

@param string $method
@param string $uri
@param string $body
@param SharedEncryptionKey $key
@param array $headers
@return RequestInterface
967160
public function createSymmetricEncryptedRequest(
        string $method,
        string $uri,
        string $body,
        SharedEncryptionKey $key,
        array $headers = []
    ): RequestInterface {
        return new Request(
            $method,
            $uri,
            $headers,
            Base64UrlSafe::encode(Simple::encrypt($body, $key))
        );
    }
581355
public static function opensslDecrypt(
        $encryptedStr,
        $key,
        $method = 'AES-256-CBC',
        $options = OPENSSL_RAW_DATA,
        $iv = self::ZERO_IV,
        $format = self::FORMAT_HEX
    )
    {
        if ($iv == self::ZERO_IV) {
            $zeroPack = pack('i*', 0);
            $iv = str_repeat($zeroPack, 4);
        }

        $encryptedStr = trim($encryptedStr);

        switch ($format) {
            case self::FORMAT_HEX:
                $encryptedStr = hex2bin($encryptedStr);
                break;
            case self::FORMAT_BASE64:
                $encryptedStr = EncodeHelper::base64Decode($encryptedStr);
                break;
            default:
                $encryptedStr = hex2bin($encryptedStr);
        }

        return trim(openssl_decrypt($encryptedStr, $method, $key, $options, $iv));
    }
758402
public function encryptResponseWithSharedKey(
        ResponseInterface $response,
        SharedEncryptionKey $key
    ): ResponseInterface {
        $encrypted = Base64UrlSafe::encode(
            Simple::encrypt((string) $response->getBody(), $key)
        );
        return $response->withBody(
            $this->adapter->stringToStream($encrypted)
        );
    }
144034
private function jsonCall($method, $uri, $body = null)
    {
        $jsonBody = null;

        if (null !== $body) {
            $jsonBody = json_encode($body);
        }

        $request = new Request($method, $uri, ['Content-Type' => 'application/json'], $jsonBody);
        $response = $this->guzzle->send($request);
        $this->lastResponse = $response;

        self::checkResponse($response);

        return json_decode($response->getBody());
    }
796657
protected function doRequest(ZendUriHttp $uri, $method, $secure = false, $headers = [], $body = '')
    {
        $logger = $this->getLogger();
        if ($logger !== null) {
            $uriString = (string) $uri;
            if (mb_strlen($body) <= 200) {
                $shortBody = (string) $body;
            } else {
                $shortBody = mb_substr($body, 0, 197) . '...';
            }
            $logger->debug(
                'Sending {method} request to {uri} with body {shortBody}',
                [
                    'uri' => $uriString,
                    'method' => $method,
                    'headers' => is_array($headers) ? $headers : (array) $headers,
                    'shortBody' => $shortBody,
                    'body' => $body,
                ]
            );
        }

        return parent::doRequest($uri, $method, $secure, $headers, $body);
    }
659567
public function run(
        string $method,
        string $uri,
        array $headers,
        string $body
    ) {
        if ($this->router === null) {
            return;
        }

        try {
            $response = $this->router->run($method, $uri, $headers, $body);
            if ($response !== null) {
                $response->output();
            }
        } catch (RouterException $e) {
            $e->getResponse()->output();
        }
    }
149281
public function createSealedRequest(
        string $method,
        string $uri,
        string $body,
        SealingPublicKey $key,
        array $headers = []
    ): RequestInterface {
        $sealed = Simple::seal(
            $body,
            $key
        );
        return new Request(
            $method,
            $uri,
            $headers,
            Base64UrlSafe::encode($sealed)
        );
    }
100611
public function createRequest($method = 'GET', $uri = null, $headers = null, $body = null, array $options = array())
    {
        $uri = '{+base_path}/' . ltrim($uri, '/');
        return parent::createRequest($method, $uri, $headers, $body, $options);
    }
138193
public static function signRequest($clientSecret, $method, $url, $body, $timestamp)
	{
		$separator = "\n";
		// Build string that need to be signed [ METHOD, URL, BODY, UNIX_TIMESTAMP ]
		$string = implode($separator, [$method, $url, $body, $timestamp]);

		// Sign
		return hash_hmac('sha256', $string, $clientSecret);
	}
1254842
public function custom(string $method, string $uri, string $body='', array $headers=[])
  {
    $this->sendRequest($this->createRequest($method,$uri), $headers);

    return !is_null($this->getResponse());
  }
645832
public function newRequest($method, $uri, $contentType = null, $body = null)
    {
        // TODO $uri whitelist (trusted domain)

        $headers = [
            'User-Agent' => $this->userAgent,
        ];
        if (!is_null($contentType)) {
            $headers['Content-Type'] = $contentType;
        }

        return new Request(
            $method,
            $uri,
            $headers,
            $body
        );
    }
644561
public function request($protocolVersion, $headers, $body, $method, $uri)
    {
        return new Messages\Message\Request\Implementation(
            $protocolVersion,
            $headers,
            $body,
            $method,
            $uri
        );
    }
991337
public function createSymmetricEncryptedResponse(
        int $status,
        string $body,
        SharedEncryptionKey $key,
        array $headers = [],
        string $version = '1.1'
    ): ResponseInterface {
        return new Response(
            $status,
            $headers,
            Base64UrlSafe::encode(Simple::encrypt($body, $key)),
            $version
        );
    }
1274918
private function createRequest(
        string $method,
        string $path,
        $body = null,
        array $headers = [],
        bool $withAuthorization = true
    ): RequestInterface {
        $uri  = $this->getSafeBaseUrl();
        $uri .= '/'.$path;

        $rawData = is_array($body) ? http_build_query($body) : $body;
        $body    = null;

        if (in_array($method, $this->getQueryMethods())) {
            if (is_string($rawData) && $rawData !== '') {
                $uri .= '?'.$rawData;
            }
        } else {
            $body = $rawData;
        }

        $baseHeaders = ['Content-Type' => 'application/x-www-form-urlencoded'];

        if ($withAuthorization) {
            $baseHeaders['Authorization'] = $this->getAuthorizationHeader();
        }

        return $this->getMessageFactory()->createRequest($method, $uri, $headers + $baseHeaders, $body);
    }
382774
public function json($method, $uri, array $data = [], array $headers = [])
    {
        $files = $this->extractFilesFromDataArray($data);

        $content = json_encode($data);

        $headers = array_merge([
            'CONTENT_LENGTH' => mb_strlen($content, '8bit'),
            'CONTENT_TYPE' => 'application/json',
            'Accept' => 'application/json',
        ], $headers);

        $this->call(
            $method, $uri, [], [], $files, $this->transformHeadersToServerVars($headers), $content
        );

        return $this;
    }
1138130
private function request($method, $uri, array $options = array())
    {
        $options['auth'] = array($this->accessKey, $this->secretKey);

        return $this->httpClient->request($method, $uri, $options);
    }
267105
public function createRequest(string $method, string $uri, array $body = []): RequestInterface
    {
        $request = $this->requestFactory->createRequest($method, $uri)
            ->withHeader('Content-Type', 'application/json')
            ->withHeader('Authorization', 'Token ' . $this->token)
            ->withHeader('X-Secret', $this->secret)
        ;

        if (!empty($body)) {
            $request = $request
                ->withBody($this->streamFactory->createStream(json_encode($body, JSON_UNESCAPED_UNICODE)))
            ;
        }

        return $request;
    }