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;
}
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);
}
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());
}
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);
}
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);
}