use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class RestfulEnclaveClientTest method encryptPayloadToRaw.
@Test
public void encryptPayloadToRaw() {
byte[] message = "HELLOW".getBytes();
PublicKey senderPublicKey = PublicKey.from("SenderPublicKey".getBytes());
byte[] encryptedKey = "encryptedKey".getBytes();
Nonce nonce = new Nonce("Nonce".getBytes());
RawTransaction rawTransaction = new RawTransaction(message, encryptedKey, nonce, senderPublicKey);
when(enclave.encryptRawPayload(message, senderPublicKey)).thenReturn(rawTransaction);
RawTransaction result = enclaveClient.encryptRawPayload(message, senderPublicKey);
assertThat(result).isNotNull();
assertThat(result).isEqualTo(rawTransaction);
verify(enclave).encryptRawPayload(message, senderPublicKey);
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class RestfulEnclaveClientTest method unencryptRawPayload.
@Test
public void unencryptRawPayload() throws Exception {
byte[] message = "HELLOW".getBytes();
PublicKey senderPublicKey = PublicKey.from("SenderPublicKey".getBytes());
byte[] encryptedKey = "encryptedKey".getBytes();
Nonce nonce = new Nonce("Nonce".getBytes());
RawTransaction rawTransaction = new RawTransaction(message, encryptedKey, nonce, senderPublicKey);
when(enclave.unencryptRawPayload(any(RawTransaction.class))).thenReturn("unencryptedRawTransaction".getBytes());
byte[] result = enclaveClient.unencryptRawPayload(rawTransaction);
assertThat(result).containsExactly("unencryptedRawTransaction".getBytes());
verify(enclave).unencryptRawPayload(any(RawTransaction.class));
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class RestfulEnclaveClientTest method encryptPayloadRawWithPrivacyGroupId.
@Test
public void encryptPayloadRawWithPrivacyGroupId() {
byte[] message = "HELLOW".getBytes();
byte[] encryptedKey = "encryptedKey".getBytes();
Nonce nonce = new Nonce("Nonce".getBytes());
PublicKey senderPublicKey = PublicKey.from("SenderPublicKey".getBytes());
List<PublicKey> recipientPublicKeys = Arrays.asList(PublicKey.from("RecipientPublicKey".getBytes()));
RawTransaction rawTransaction = new RawTransaction(message, encryptedKey, nonce, senderPublicKey);
EncodedPayload encodedPayloadWithGroupId = EncodedPayload.Builder.from(Fixtures.createSample()).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
List<AffectedTransaction> affectedTransactions = List.of(AffectedTransaction.Builder.create().withHash("hash".getBytes()).withPayload(encodedPayloadWithGroupId).build());
final PrivacyMetadata privacyMetaData = PrivacyMetadata.Builder.create().withPrivacyMode(PrivacyMode.PARTY_PROTECTION).withAffectedTransactions(affectedTransactions).withPrivacyGroupId(PrivacyGroup.Id.fromBytes("group".getBytes())).build();
when(enclave.encryptPayload(any(RawTransaction.class), any(List.class), any())).thenReturn(encodedPayloadWithGroupId);
EncodedPayload result = enclaveClient.encryptPayload(rawTransaction, recipientPublicKeys, privacyMetaData);
assertThat(result).isNotNull();
byte[] encodedResult = payloadEncoder.encode(result);
byte[] encodedEncodedPayload = payloadEncoder.encode(encodedPayloadWithGroupId);
assertThat(encodedResult).isEqualTo(encodedEncodedPayload);
ArgumentCaptor<PrivacyMetadata> argumentCaptor = ArgumentCaptor.forClass(PrivacyMetadata.class);
verify(enclave).encryptPayload(any(RawTransaction.class), any(List.class), argumentCaptor.capture());
final PrivacyMetadata passingThroughPrivacyData = argumentCaptor.getValue();
assertThat(passingThroughPrivacyData.getPrivacyGroupId()).isPresent().get().isEqualTo(PrivacyGroup.Id.fromBytes("group".getBytes()));
assertThat(passingThroughPrivacyData.getPrivacyMode()).isEqualTo(privacyMetaData.getPrivacyMode());
assertThat(passingThroughPrivacyData.getAffectedContractTransactions()).isEqualTo(privacyMetaData.getAffectedContractTransactions());
assertThat(passingThroughPrivacyData.getExecHash()).isEqualTo(privacyMetaData.getExecHash());
}
use of com.quorum.tessera.encryption.Nonce 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.Nonce 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);
}
Aggregations