use of com.google.crypto.tink.Aead in project tink by google.
the class ChaCha20Poly1305KeyManagerTest method testCiphertextSize.
@Test
public void testCiphertextSize() throws Exception {
Aead aead = new ChaCha20Poly1305KeyManager().getPrimitive(createChaCha20Poly1305Key(32), Aead.class);
byte[] plaintext = "plaintext".getBytes(UTF_8);
byte[] associatedData = "associatedData".getBytes(UTF_8);
byte[] ciphertext = aead.encrypt(plaintext, associatedData);
assertEquals(12 + /* IV_SIZE */
plaintext.length + 16, /* TAG_SIZE */
ciphertext.length);
}
use of com.google.crypto.tink.Aead 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);
}
use of com.google.crypto.tink.Aead in project tink by google.
the class KmsEnvelopeAeadKeyManagerTest method createKey_multipleKeysWithSameKek.
@Test
public void createKey_multipleKeysWithSameKek() throws Exception {
String kekUri = FakeKmsClient.createFakeKeyUri();
KeyTemplate dekTemplate = AesCtrHmacAeadKeyManager.aes128CtrHmacSha256Template();
KmsEnvelopeAeadKey key1 = factory.createKey(KmsEnvelopeAeadKeyManager.createKeyFormat(kekUri, dekTemplate));
Aead aead1 = manager.getPrimitive(key1, Aead.class);
KmsEnvelopeAeadKey key2 = factory.createKey(KmsEnvelopeAeadKeyManager.createKeyFormat(kekUri, dekTemplate));
Aead aead2 = manager.getPrimitive(key2, Aead.class);
byte[] plaintext = Random.randBytes(20);
byte[] associatedData = Random.randBytes(20);
assertThat(aead1.decrypt(aead2.encrypt(plaintext, associatedData), associatedData)).isEqualTo(plaintext);
}
use of com.google.crypto.tink.Aead in project tink by google.
the class KmsEnvelopeAeadKeyManagerTest method getPrimitive.
@Test
public void getPrimitive() throws Exception {
String kekUri = FakeKmsClient.createFakeKeyUri();
KeyTemplate dekTemplate = AesCtrHmacAeadKeyManager.aes128CtrHmacSha256Template();
KmsEnvelopeAeadKey key = factory.createKey(KmsEnvelopeAeadKeyManager.createKeyFormat(kekUri, dekTemplate));
Aead aead = manager.getPrimitive(key, Aead.class);
TestUtil.runBasicAeadTests(aead);
}
use of com.google.crypto.tink.Aead in project tink by google.
the class KmsEnvelopeAeadTest method encryptDecryptMissingAd_fails.
@Test
public void encryptDecryptMissingAd_fails() throws GeneralSecurityException {
Aead remoteAead = this.generateNewRemoteAead();
KmsEnvelopeAead envAead = new KmsEnvelopeAead(KeyTemplateProtoConverter.toProto(KeyTemplates.get("AES128_EAX")), remoteAead);
byte[] plaintext = "helloworld".getBytes(UTF_8);
byte[] associatedData = "envelope_ad".getBytes(UTF_8);
byte[] ciphertext = envAead.encrypt(plaintext, associatedData);
assertThrows(GeneralSecurityException.class, () -> envAead.decrypt(ciphertext, EMPTY_ADD));
}
Aggregations