@Test public void computeSharedKeySodiumReturnsSuccess() { when(sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( any(byte[].class), any(byte[].class), any(byte[].class))) .thenReturn(1); final SharedKey result = kalium.computeSharedKey(publicKey, privateKey); assertThat(result).isNotNull(); assertThat(result.getKeyBytes()).isEqualTo(new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]); verify(sodium) .crypto_box_curve25519xsalsa20poly1305_beforenm( any(byte[].class), any(byte[].class), any(byte[].class)); }
@Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] output = new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( output, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("Kalium could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(output); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; }
Kalium implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] output = new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( output, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("Kalium could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(output); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } }
Kalium implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] output = new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( output, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("Kalium could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(output); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } Kalium(final NaCl.Sodium sodium); }
Kalium implements Encryptor { @Override public SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] output = new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( output, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("Kalium could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(output); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } 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 SharedKey computeSharedKey(final PublicKey publicKey, final PrivateKey privateKey) { final byte[] output = new byte[CRYPTO_BOX_CURVE25519XSALSA20POLY1305_BEFORENMBYTES]; LOGGER.debug("Computing the shared key for public key {} and private key {}", publicKey, privateKey); final int sodiumResult = this.sodium.crypto_box_curve25519xsalsa20poly1305_beforenm( output, publicKey.getKeyBytes(), privateKey.getKeyBytes()); if (sodiumResult == -1) { LOGGER.error("Could not compute the shared key for pub {} and priv {}", publicKey, privateKey); throw new EncryptorException("Kalium could not compute the shared key"); } final SharedKey sharedKey = SharedKey.from(output); LOGGER.debug("Computed shared key {} for pub {} and priv {}", sharedKey, publicKey, privateKey); return sharedKey; } 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();  }