use of com.google.crypto.tink.proto.XChaCha20Poly1305Key in project tink by google.
the class XChaCha20Poly1305KeyManagerTest method testDeriveKey.
@Test
public void testDeriveKey() throws Exception {
final int keySize = 32;
byte[] keyMaterial = Random.randBytes(100);
XChaCha20Poly1305Key key = factory.deriveKey(XChaCha20Poly1305KeyFormat.newBuilder().setVersion(0).build(), new ByteArrayInputStream(keyMaterial));
assertThat(key.getKeyValue()).hasSize(keySize);
for (int i = 0; i < keySize; ++i) {
assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
}
}
use of com.google.crypto.tink.proto.XChaCha20Poly1305Key in project tink by google.
the class XChaCha20Poly1305KeyManagerTest method getPrimitive.
@Test
public void getPrimitive() throws Exception {
XChaCha20Poly1305Key key = factory.createKey(XChaCha20Poly1305KeyFormat.getDefaultInstance());
Aead managerAead = manager.getPrimitive(key, Aead.class);
Aead directAead = new XChaCha20Poly1305(key.getKeyValue().toByteArray());
byte[] plaintext = Random.randBytes(20);
byte[] associatedData = Random.randBytes(20);
assertThat(directAead.decrypt(managerAead.encrypt(plaintext, associatedData), associatedData)).isEqualTo(plaintext);
}
Aggregations