@Test public void sealAfterPrecomputationSodiumReturnsSuccess() { doReturn(1) .when(this.secretBox) .cryptoBoxAfternm( any(byte[].class), any(byte[].class), anyInt(), any(byte[].class), eq(sharedKey.getKeyBytes())); final byte[] result = this.jnacl.sealAfterPrecomputation(message, nonce, sharedKey); assertThat(result).isNotEmpty(); verify(this.secretBox) .cryptoBoxAfternm(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 = new byte[message.length + crypto_secretbox_ZEROBYTES]; final byte[] output = new byte[message.length + crypto_secretbox_ZEROBYTES]; LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); System.arraycopy(message, 0, paddedMessage, crypto_secretbox_ZEROBYTES, message.length); final int jnaclResult = secretBox.cryptoBoxAfternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("jnacl could not seal the payload using the shared key"); } LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, crypto_secretbox_BOXZEROBYTES); }
Jnacl implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = new byte[message.length + crypto_secretbox_ZEROBYTES]; final byte[] output = new byte[message.length + crypto_secretbox_ZEROBYTES]; LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); System.arraycopy(message, 0, paddedMessage, crypto_secretbox_ZEROBYTES, message.length); final int jnaclResult = secretBox.cryptoBoxAfternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("jnacl could not seal the payload using the shared key"); } LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, crypto_secretbox_BOXZEROBYTES); } }
Jnacl implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = new byte[message.length + crypto_secretbox_ZEROBYTES]; final byte[] output = new byte[message.length + crypto_secretbox_ZEROBYTES]; LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); System.arraycopy(message, 0, paddedMessage, crypto_secretbox_ZEROBYTES, message.length); final int jnaclResult = secretBox.cryptoBoxAfternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("jnacl could not seal the payload using the shared key"); } LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, crypto_secretbox_BOXZEROBYTES); } Jnacl(final SecureRandom secureRandom, final SecretBox secretBox); }
Jnacl implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = new byte[message.length + crypto_secretbox_ZEROBYTES]; final byte[] output = new byte[message.length + crypto_secretbox_ZEROBYTES]; LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); System.arraycopy(message, 0, paddedMessage, crypto_secretbox_ZEROBYTES, message.length); final int jnaclResult = secretBox.cryptoBoxAfternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("jnacl could not seal the payload using the shared key"); } LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, crypto_secretbox_BOXZEROBYTES); } Jnacl(final SecureRandom secureRandom, final SecretBox secretBox); @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[] cipherText, final Nonce nonce, final SharedKey sharedKey); @Override Nonce randomNonce(); @Override KeyPair generateNewKeys(); @Override SharedKey createSingleKey(); }
Jnacl implements Encryptor { @Override public byte[] sealAfterPrecomputation(final byte[] message, final Nonce nonce, final SharedKey sharedKey) { final byte[] paddedMessage = new byte[message.length + crypto_secretbox_ZEROBYTES]; final byte[] output = new byte[message.length + crypto_secretbox_ZEROBYTES]; LOGGER.debug("Sealing message using nonce {} and shared key {}", nonce, sharedKey); System.arraycopy(message, 0, paddedMessage, crypto_secretbox_ZEROBYTES, message.length); final int jnaclResult = secretBox.cryptoBoxAfternm( output, paddedMessage, paddedMessage.length, nonce.getNonceBytes(), sharedKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not create sealed payload using shared key {}", sharedKey); throw new EncryptorException("jnacl could not seal the payload using the shared key"); } LOGGER.debug( "Created sealed payload using nonce {} and shared key {}", nonce, sharedKey); return extract(output, crypto_secretbox_BOXZEROBYTES); } Jnacl(final SecureRandom secureRandom, final SecretBox secretBox); @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[] cipherText, final Nonce nonce, final SharedKey sharedKey); @Override Nonce randomNonce(); @Override KeyPair generateNewKeys(); @Override SharedKey createSingleKey();  }