use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.
the class JnaclIT method randomKeyCanEncryptAndDecrpytPayload.
@Test
public void randomKeyCanEncryptAndDecrpytPayload() {
final String payload = "Hello world";
final byte[] payloadBytes = payload.getBytes(UTF_8);
final Nonce nonce = jnacl.randomNonce();
final SharedKey symmentricKey = jnacl.createSingleKey();
final byte[] encryptedPayload = jnacl.sealAfterPrecomputation(payloadBytes, nonce, symmentricKey);
final byte[] decryptedPayload = jnacl.openAfterPrecomputation(encryptedPayload, nonce, symmentricKey);
final String decryptedMessage = new String(decryptedPayload, UTF_8);
assertThat(decryptedMessage).isEqualTo(payload);
}
use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.
the class KaliumIT method sharedKeyPubaprivbEqualsPrivapubb.
@Test
public void sharedKeyPubaprivbEqualsPrivapubb() {
final SharedKey sharedKey = kalium.computeSharedKey(keypairOne.getPublicKey(), keypairTwo.getPrivateKey());
final SharedKey secondSharedKey = kalium.computeSharedKey(keypairTwo.getPublicKey(), keypairOne.getPrivateKey());
assertThat(sharedKey).isEqualTo(secondSharedKey);
}
use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.
the class KaliumTest method computeSharedKeySodiumReturnsSuccess.
@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));
}
use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.
the class KaliumIT method randomKeyCanEncryptAndDecrpytPayload.
@Test
public void randomKeyCanEncryptAndDecrpytPayload() {
final String payload = "Hello world";
final byte[] payloadBytes = payload.getBytes(UTF_8);
final Nonce nonce = kalium.randomNonce();
final SharedKey symmentricKey = kalium.createSingleKey();
final byte[] encryptedPayload = kalium.sealAfterPrecomputation(payloadBytes, nonce, symmentricKey);
final byte[] decryptedPayload = kalium.openAfterPrecomputation(encryptedPayload, nonce, symmentricKey);
final String decryptedMessage = new String(decryptedPayload, UTF_8);
assertThat(decryptedMessage).isEqualTo(payload);
}
use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.
the class KaliumIT method encryptAndDecryptPayloadUsingSameKeys.
@Test
public void encryptAndDecryptPayloadUsingSameKeys() {
final String payload = "Hello world";
final SharedKey sharedKey = kalium.computeSharedKey(keypairOne.getPublicKey(), keypairTwo.getPrivateKey());
final byte[] payloadBytes = payload.getBytes(UTF_8);
final Nonce nonce = kalium.randomNonce();
final byte[] encryptedPayload = kalium.sealAfterPrecomputation(payloadBytes, nonce, sharedKey);
final byte[] decryptedPayload = kalium.openAfterPrecomputation(encryptedPayload, nonce, sharedKey);
final String decryptedMessage = new String(decryptedPayload, UTF_8);
assertThat(decryptedMessage).isEqualTo(payload);
}