Search in sources :

Example 1 with AesGcmSiv

use of com.google.crypto.tink.aead.subtle.AesGcmSiv in project tink by google.

the class AesGcmSivKeyManagerTest method getPrimitive.

@Test
public void getPrimitive() throws Exception {
    AesGcmSivKey key = factory.createKey(AesGcmSivKeyFormat.newBuilder().setKeySize(16).build());
    Aead managerAead = manager.getPrimitive(key, Aead.class);
    Aead directAead = new AesGcmSiv(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) AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) AesGcmSiv(com.google.crypto.tink.aead.subtle.AesGcmSiv) Test(org.junit.Test)

Aggregations

Aead (com.google.crypto.tink.Aead)1 AesGcmSiv (com.google.crypto.tink.aead.subtle.AesGcmSiv)1 AesGcmSivKey (com.google.crypto.tink.proto.AesGcmSivKey)1 Test (org.junit.Test)1