private function encryptBody(string $request, string $publicKey, string $nonce) : string
    {
        if (\strlen($publicKey) !== SODIUM_CRYPTO_BOX_PUBLICKEYBYTES) {
            throw new InvalidArgumentException(sprintf("Public key should be %d bytes.", SODIUM_CRYPTO_BOX_PUBLICKEYBYTES));
        }

        if (\strlen($nonce) !== SODIUM_CRYPTO_BOX_NONCEBYTES) {
            throw new InvalidArgumentException(sprintf("Nonce should be %d bytes.", SODIUM_CRYPTO_BOX_NONCEBYTES));
        }

        try {
            $keypair = new Keypair(
                $this->secretKey,
                $publicKey
            );
            return \sodium_crypto_box(
                $request,
                $nonce,
                $keypair->getSodiumKeypair()
            );
        } catch (SodiumException $e) {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
private function encryptBody(string $request, string $publicKey, string $nonce) : string
    {
        if (\strlen($publicKey) !== SODIUM_CRYPTO_BOX_PUBLICKEYBYTES) {
            throw new InvalidArgumentException(sprintf("Public key should be %d bytes.", SODIUM_CRYPTO_BOX_PUBLICKEYBYTES));
        }

        if (\strlen($nonce) !== SODIUM_CRYPTO_BOX_NONCEBYTES) {
            throw new InvalidArgumentException(sprintf("Nonce should be %d bytes.", SODIUM_CRYPTO_BOX_NONCEBYTES));
        }

        try {
            $keypair = new Keypair(
                $this->secretKey,
                $publicKey
            );
            return \sodium_crypto_box(
                $request,
                $nonce,
                $keypair->getSodiumKeypair()
            );
        } catch (SodiumException $e) {
            throw new InvalidArgumentException($e->getMessage());
        }
    }
private function encryptBody ( string $ request , string $ publicKey , string $ nonce ) : string { if ( \ strlen ( $ publicKey ) !== SODIUM_CRYPTO_BOX_PUBLICKEYBYTES ) { throw new InvalidArgumentException ( sprintf ( "Public key should be %d bytes." , SODIUM_CRYPTO_BOX_PUBLICKEYBYTES ) ) ; } if ( \ strlen ( $ nonce ) !== SODIUM_CRYPTO_BOX_NONCEBYTES ) { throw new InvalidArgumentException ( sprintf ( "Nonce should be %d bytes." , SODIUM_CRYPTO_BOX_NONCEBYTES ) ) ; } try { $ keypair = new Keypair ( $ this -> secretKey , $ publicKey ) ; return \ sodium_crypto_box ( $ request , $ nonce , $ keypair -> getSodiumKeypair ( ) ) ; } catch ( SodiumException $ e ) { throw new InvalidArgumentException ( $ e -> getMessage ( ) ) ; } }
Encrypts a request

@param string $request   The raw HTTP request as a string
@param string $nonce     Optional nonce. If not provided, a 24 byte nonce will be generated
@return string

@throws InvalidArguementException
Encrypts a request