@Test public void sealAfterPrecomputationSodiumReturnsSuccess() { doReturn(1) .when(this.sodium) .crypto_box_curve25519xsalsa20poly1305_afternm( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), eq(sharedKey.getKeyBytes())); final byte[] result = kalium.sealAfterPrecomputation(message, nonce, sharedKey); assertThat(result).isNotEmpty(); verify(this.sodium) .crypto_box_curve25519xsalsa20poly1305_afternm( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), any(byte[].class)); }
@Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", sharedKey); LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_afternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("Kalium could not seal the payload using the shared key"); } LOGGER.info("Created sealed payload for shared key {}", sharedKey); LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES); }
Kalium implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", sharedKey); LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_afternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("Kalium could not seal the payload using the shared key"); } LOGGER.info("Created sealed payload for shared key {}", sharedKey); LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES); } }
Kalium implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", sharedKey); LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_afternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("Kalium could not seal the payload using the shared key"); } LOGGER.info("Created sealed payload for shared key {}", sharedKey); LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BOXZEROBYTES); } Kalium(final NaCl.Sodium sodium); }
Kalium implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", sharedKey); LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_afternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("Kalium could not seal the payload using the shared key"); } LOGGER.info("Created sealed payload for shared key {}", sharedKey); LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); 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(); }
Kalium implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = pad(message, CRYPTO_BOX_CURVE25519XSALSA20POLY1305_ZEROBYTES); final byte[] output = new byte[paddedMessage.length]; LOGGER.info("Sealing message using public key {}", sharedKey); LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_afternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("Kalium could not seal the payload using the shared key"); } LOGGER.info("Created sealed payload for shared key {}", sharedKey); LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); 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();  }