### Question:
Kalium implements Encryptor { @Override public byte[] seal( final byte[] message, final Nonce nonce, final PublicKey publicKey, final PrivateKey privateKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", publicKey); LOGGER.debug( "Sealing message using nonce {}, public key {} and private key {}", nonce, publicKey, privateKey); final int sodiumResult = sodium.crypto_box_curve25519xsalsa20poly1305( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using public key {} and private key {}", publicKey, privateKey); throw new EncryptorException("Kalium could not seal the payload using the provided keys directly"); } LOGGER.info("Created sealed payload for public key {}", publicKey); LOGGER.debug( "Created sealed payload using nonce {}, public key {} and private key {}", nonce, publicKey, privateKey); return extract(output, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES); } Kalium(final NaCl.Sodium sodium); @Override SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey); @Override byte[] seal(
            final byte[] message, final Nonce nonce, final PublicKey publicKey, final PrivateKey privateKey); @Override byte[] open(
            final byte[] cipherText, final Nonce nonce, final PublicKey publicKey, final PrivateKey privateKey); @Override byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey); @Override byte[] openAfterPrecomputation(final byte[] encryptedPayload, final Nonce nonce, final SharedKey sharedKey); @Override Nonce randomNonce(); @Override KeyPair generateNewKeys(); @Override SharedKey createSingleKey();  }### Answer:
@Test public void sealUsingKeysThrowsExceptionOnFailure() { doReturn(-1) .when(this.sodium) .crypto_box_curve25519xsalsa20poly1305( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), eq(publicKey.getKeyBytes()), eq(privateKey.getKeyBytes())); final Throwable kaclEx = catchThrowable(() -> this.kalium.seal(message, nonce, publicKey, privateKey)); assertThat(kaclEx) .isInstanceOf(EncryptorException.class) .hasMessage("Kalium could not seal the payload using the provided keys directly"); verify(this.sodium) .crypto_box_curve25519xsalsa20poly1305( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), any(byte[].class), any(byte[].class)); }
@Test public void sealUsingKeysSodiumReturnsSuccess() { doReturn(1) .when(this.sodium) .crypto_box_curve25519xsalsa20poly1305( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), eq(publicKey.getKeyBytes()), eq(privateKey.getKeyBytes())); final byte[] results = this.kalium.seal(message, nonce, publicKey, privateKey); assertThat(results).isNotEmpty(); verify(this.sodium) .crypto_box_curve25519xsalsa20poly1305( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), any(byte[].class), any(byte[].class)); }