Search in sources :

Example 6 with SharedKey

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);
}
Also used : Nonce(com.quorum.tessera.encryption.Nonce) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 7 with SharedKey

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);
}
Also used : SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 8 with SharedKey

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));
}
Also used : SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 9 with SharedKey

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);
}
Also used : Nonce(com.quorum.tessera.encryption.Nonce) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 10 with SharedKey

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);
}
Also used : Nonce(com.quorum.tessera.encryption.Nonce) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Aggregations

SharedKey (com.quorum.tessera.encryption.SharedKey)11 Test (org.junit.Test)10 Nonce (com.quorum.tessera.encryption.Nonce)4 KeyPair (com.quorum.tessera.encryption.KeyPair)1