use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class StagingTransactionUtilsTest method testFromRawPayload.
@Test
public void testFromRawPayload() {
final TxHash affectedHash = new TxHash("TX2");
final EncodedPayload encodedPayload = EncodedPayload.Builder.create().withSenderKey(sender).withCipherText("cipherText".getBytes()).withCipherTextNonce(new Nonce("nonce".getBytes())).withRecipientBoxes(List.of("box1".getBytes(), "box2".getBytes())).withRecipientNonce(new Nonce("recipientNonce".getBytes())).withRecipientKeys(List.of(recipient1)).withPrivacyMode(PrivacyMode.PARTY_PROTECTION).withAffectedContractTransactions(Map.of(affectedHash, "somesecurityHash".getBytes())).build();
// FIXME: Cross module depenency!!!
final String messageHash = Base64.getEncoder().encodeToString(payloadDigest.digest(encodedPayload.getCipherText()));
final byte[] raw = encoder.encode(encodedPayload);
StagingTransaction result = StagingTransactionUtils.fromRawPayload(raw, EncodedPayloadCodec.current());
assertThat(result).isNotNull();
assertThat(result.getHash()).isEqualTo(messageHash);
assertThat(result.getPayload()).isEqualTo(raw);
assertThat(result.getPrivacyMode()).isEqualTo(PrivacyMode.PARTY_PROTECTION);
assertThat(result.getValidationStage()).isNull();
assertThat(result.getAffectedContractTransactions()).hasSize(1);
result.getAffectedContractTransactions().forEach(atx -> {
assertThat(atx.getHash()).isEqualTo(affectedHash.encodeToBase64());
assertThat(atx.getSourceTransaction()).isEqualTo(result);
});
}
use of com.quorum.tessera.encryption.Nonce in project tessera by ConsenSys.
the class KeyEncryptorTest method encryptingKeyReturnsCorrectJson.
@Test
public void encryptingKeyReturnsCorrectJson() {
final PrivateKey key = PrivateKey.from(new byte[] { 1, 2, 3, 4, 5 });
final char[] password = "pass".toCharArray();
final ArgonResult result = new ArgonResult(new com.quorum.tessera.argon2.ArgonOptions("i", 1, 1, 1), new byte[] {}, new byte[] {});
doReturn(result).when(argon2).hash(eq(password), any(byte[].class));
doReturn(new Nonce(new byte[] {})).when(encryptor).randomNonce();
doReturn(new byte[] {}).when(encryptor).sealAfterPrecomputation(any(byte[].class), any(Nonce.class), any(SharedKey.class));
final PrivateKeyData privateKey = this.keyEncryptor.encryptPrivateKey(key, password, null);
final ArgonOptions aopts = privateKey.getArgonOptions();
assertThat(privateKey.getSbox()).isNotNull();
assertThat(privateKey.getAsalt()).isNotNull();
assertThat(privateKey.getSnonce()).isNotNull();
assertThat(aopts).isNotNull();
assertThat(aopts.getMemory()).isNotNull();
assertThat(aopts.getParallelism()).isNotNull();
assertThat(aopts.getIterations()).isNotNull();
assertThat(aopts.getAlgorithm()).isNotNull();
verify(argon2).hash(eq(password), any(byte[].class));
verify(encryptor).randomNonce();
verify(encryptor).sealAfterPrecomputation(any(byte[].class), any(Nonce.class), any(SharedKey.class));
}
Aggregations