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]);
}
}
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);
}
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);
}
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]);
}
}
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]);
}
}
Aggregations