Search in sources :

Example 6 with AesGcmSivKey

use of com.google.crypto.tink.proto.AesGcmSivKey in project tink by google.

the class AesGcmSivKeyManagerTest method createKey_16Bytes.

@Test
public void createKey_16Bytes() throws Exception {
    AesGcmSivKey key = factory.createKey(AesGcmSivKeyFormat.newBuilder().setKeySize(16).build());
    assertThat(key.getKeyValue()).hasSize(16);
}
Also used : AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) Test(org.junit.Test)

Example 7 with AesGcmSivKey

use of com.google.crypto.tink.proto.AesGcmSivKey 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

AesGcmSivKey (com.google.crypto.tink.proto.AesGcmSivKey)7 Test (org.junit.Test)7 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Aead (com.google.crypto.tink.Aead)2 AesGcmSiv (com.google.crypto.tink.aead.subtle.AesGcmSiv)1