use of com.google.crypto.tink.subtle.XChaCha20Poly1305 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