Search in sources :

Example 1 with SharedKey

use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.

the class EllipticalCurveEncryptor method createSingleKey.

@Override
public SharedKey createSingleKey() {
    LOGGER.debug("Generating random key");
    final byte[] keyBytes = new byte[sharedKeyLength];
    this.secureRandom.nextBytes(keyBytes);
    final SharedKey key = SharedKey.from(keyBytes);
    LOGGER.debug("Random key generated");
    LOGGER.debug("Generated key with value {}", key);
    return key;
}
Also used : SharedKey(com.quorum.tessera.encryption.SharedKey)

Example 2 with SharedKey

use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.

the class EllipticalCurveEncryptorTest method createSingleKey.

@Test
public void createSingleKey() {
    SharedKey sharedKey = encryptor.createSingleKey();
    assertThat(sharedKey).isNotNull();
    assertThat(sharedKey.getKeyBytes()).hasSize(32);
}
Also used : SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 3 with SharedKey

use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.

the class EllipticalCurveEncryptorTest method computeSharedKey.

@Test
public void computeSharedKey() {
    KeyPair keyPair1 = encryptor.generateNewKeys();
    KeyPair keyPair2 = encryptor.generateNewKeys();
    SharedKey sharedPub1Priv2 = encryptor.computeSharedKey(keyPair1.getPublicKey(), keyPair2.getPrivateKey());
    SharedKey sharedPriv1Pub2 = encryptor.computeSharedKey(keyPair2.getPublicKey(), keyPair1.getPrivateKey());
    assertEquals(sharedPub1Priv2, sharedPriv1Pub2);
    LOGGER.info("SharedKey: {}", sharedPriv1Pub2.encodeToBase64());
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 4 with SharedKey

use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.

the class JnaclIT method sharedKeyPubaprivbEqualsPrivapubb.

@Test
public void sharedKeyPubaprivbEqualsPrivapubb() {
    final SharedKey sharedKey = jnacl.computeSharedKey(keypairOne.getPublicKey(), keypairTwo.getPrivateKey());
    final SharedKey secondSharedKey = jnacl.computeSharedKey(keypairTwo.getPublicKey(), keypairOne.getPrivateKey());
    assertThat(sharedKey).isEqualTo(secondSharedKey);
}
Also used : SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 5 with SharedKey

use of com.quorum.tessera.encryption.SharedKey in project tessera by ConsenSys.

the class JnaclIT method encryptAndDecryptPayloadUsingSameKeys.

@Test
public void encryptAndDecryptPayloadUsingSameKeys() {
    final String payload = "Hello world";
    final SharedKey sharedKey = jnacl.computeSharedKey(keypairOne.getPublicKey(), keypairTwo.getPrivateKey());
    final byte[] payloadBytes = payload.getBytes(UTF_8);
    final Nonce nonce = jnacl.randomNonce();
    final byte[] encryptedPayload = jnacl.sealAfterPrecomputation(payloadBytes, nonce, sharedKey);
    final byte[] decryptedPayload = jnacl.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