@Test public void computeSharedKeySodiumReturnsSuccess() { doReturn(1).when(this.secretBox).cryptoBoxBeforenm(any(byte[].class), any(byte[].class), any(byte[].class)); final SharedKey result = this.jnacl.computeSharedKey(publicKey, privateKey); assertThat(result).isNotNull(); assertThat(result.getKeyBytes()).isEqualTo(new byte[crypto_secretbox_BEFORENMBYTES]); verify(this.secretBox).cryptoBoxBeforenm(any(byte[].class), any(byte[].class), any(byte[].class)); }
@Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] precomputed = new byte[crypto_secretbox_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int jnaclResult = secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("jnacl could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(precomputed); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; }
Jnacl implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] precomputed = new byte[crypto_secretbox_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int jnaclResult = secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("jnacl could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(precomputed); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } }
Jnacl implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] precomputed = new byte[crypto_secretbox_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int jnaclResult = secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("jnacl could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(precomputed); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } Jnacl(final SecureRandom secureRandom, final SecretBox secretBox); }
Jnacl implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] precomputed = new byte[crypto_secretbox_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int jnaclResult = secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("jnacl could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(precomputed); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } 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 SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] precomputed = new byte[crypto_secretbox_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int jnaclResult = secretBox.cryptoBoxBeforenm(precomputed, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (jnaclResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("jnacl could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(precomputed); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } 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();  }