Search in sources :

Example 1 with AesGcmSivKey

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

the class AesGcmSivKeyManagerTest method testDeriveKey_justEnoughKeyMaterial.

@Test
public void testDeriveKey_justEnoughKeyMaterial() throws Exception {
    final int keySize = 32;
    byte[] keyMaterial = Random.randBytes(32);
    AesGcmSivKey key = factory.deriveKey(AesGcmSivKeyFormat.newBuilder().setVersion(0).setKeySize(keySize).build(), new ByteArrayInputStream(keyMaterial));
    assertThat(key.getKeyValue()).hasSize(keySize);
    for (int i = 0; i < keySize; ++i) {
        assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) Test(org.junit.Test)

Example 2 with AesGcmSivKey

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

the class AesGcmSivKeyManagerTest method testCiphertextSize.

@Test
public void testCiphertextSize() throws Exception {
    AesGcmSivKey key = factory.createKey(AesGcmSivKeyFormat.newBuilder().setKeySize(32).build());
    Aead aead = new AesGcmSivKeyManager().getPrimitive(key, Aead.class);
    byte[] plaintext = "plaintext".getBytes(UTF_8);
    byte[] associatedData = "associatedData".getBytes(UTF_8);
    byte[] ciphertext = aead.encrypt(plaintext, associatedData);
    assertThat(ciphertext.length).isEqualTo(12 + /* IV_SIZE */
    plaintext.length + 16);
}
Also used : Aead(com.google.crypto.tink.Aead) AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) Test(org.junit.Test)

Example 3 with AesGcmSivKey

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

the class AesGcmSivKeyManagerTest method createKey_32Bytes.

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

Example 4 with AesGcmSivKey

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

the class AesGcmSivKeyManagerTest method testDeriveKey_size32.

@Test
public void testDeriveKey_size32() throws Exception {
    final int keySize = 32;
    byte[] keyMaterial = Random.randBytes(100);
    AesGcmSivKey key = factory.deriveKey(AesGcmSivKeyFormat.newBuilder().setVersion(0).setKeySize(keySize).build(), new ByteArrayInputStream(keyMaterial));
    assertThat(key.getKeyValue()).hasSize(keySize);
    for (int i = 0; i < keySize; ++i) {
        assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) Test(org.junit.Test)

Example 5 with AesGcmSivKey

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

the class AesGcmSivKeyManagerTest method testDeriveKey_size16.

@Test
public void testDeriveKey_size16() throws Exception {
    final int keySize = 16;
    byte[] keyMaterial = Random.randBytes(100);
    AesGcmSivKey key = factory.deriveKey(AesGcmSivKeyFormat.newBuilder().setVersion(0).setKeySize(keySize).build(), new ByteArrayInputStream(keyMaterial));
    assertThat(key.getKeyValue()).hasSize(keySize);
    for (int i = 0; i < keySize; ++i) {
        assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AesGcmSivKey(com.google.crypto.tink.proto.AesGcmSivKey) 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