Search in sources :

Example 1 with XChaCha20Poly1305

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);
}
Also used : Aead(com.google.crypto.tink.Aead) XChaCha20Poly1305Key(com.google.crypto.tink.proto.XChaCha20Poly1305Key) XChaCha20Poly1305(com.google.crypto.tink.subtle.XChaCha20Poly1305) Test(org.junit.Test)

Aggregations

Aead (com.google.crypto.tink.Aead)1 XChaCha20Poly1305Key (com.google.crypto.tink.proto.XChaCha20Poly1305Key)1 XChaCha20Poly1305 (com.google.crypto.tink.subtle.XChaCha20Poly1305)1 Test (org.junit.Test)1