use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class JsonKeysetWriterTest method testWrite_singleKey_shouldWork.
@Test
public void testWrite_singleKey_shouldWork() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetHandle handle1 = KeysetHandle.generateNew(template);
testWrite_shouldWork(handle1);
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class JsonKeysetWriterTest method testWriteEncrypted_shouldWork.
private void testWriteEncrypted_shouldWork(KeysetHandle handle1) throws Exception {
// Encrypt the keyset with an AeadKey.
KeyTemplate masterKeyTemplate = AeadKeyTemplates.AES128_EAX;
Aead masterKey = Registry.getPrimitive(Registry.newKeyData(masterKeyTemplate));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
handle1.write(JsonKeysetWriter.withOutputStream(outputStream), masterKey);
KeysetHandle handle2 = KeysetHandle.read(JsonKeysetReader.withInputStream(new ByteArrayInputStream(outputStream.toByteArray())), masterKey);
assertKeysetHandle(handle1, handle2);
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class KmsEnvelopeAeadKeyManagerWithGcpTest method testGcpKmsKeyRestricted.
@Test
public void testGcpKmsKeyRestricted() throws Exception {
KeyTemplate dekTemplate = AeadKeyTemplates.AES128_CTR_HMAC_SHA256;
KeysetHandle keysetHandle = KeysetHandle.generateNew(AeadKeyTemplates.createKmsEnvelopeAeadKeyTemplate(TestUtil.RESTRICTED_CRYPTO_KEY_URI, dekTemplate));
TestUtil.runBasicAeadTests(keysetHandle.getPrimitive(Aead.class));
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class AeadKeyTemplatesTest method testCreateKmsEnvelopeAeadKeyTemplate.
@Test
public void testCreateKmsEnvelopeAeadKeyTemplate() throws Exception {
// Intentionally using "weird" or invalid values for parameters,
// to test that the function correctly puts them in the resulting template.
String kekUri = "some example KEK URI";
KeyTemplate dekTemplate = AeadKeyTemplates.AES256_GCM;
KeyTemplate template = AeadKeyTemplates.createKmsEnvelopeAeadKeyTemplate(kekUri, dekTemplate);
assertEquals(new KmsEnvelopeAeadKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
KmsEnvelopeAeadKeyFormat format = KmsEnvelopeAeadKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(kekUri, format.getKekUri());
assertEquals(dekTemplate.toString(), format.getDekTemplate().toString());
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class AeadKeyTemplatesTest method aes256CtrHmacSha256.
@Test
public void aes256CtrHmacSha256() throws Exception {
KeyTemplate template = AeadKeyTemplates.AES256_CTR_HMAC_SHA256;
assertEquals(new AesCtrHmacAeadKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
AesCtrHmacAeadKeyFormat format = AesCtrHmacAeadKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertTrue(format.hasAesCtrKeyFormat());
assertTrue(format.getAesCtrKeyFormat().hasParams());
assertEquals(32, format.getAesCtrKeyFormat().getKeySize());
assertEquals(16, format.getAesCtrKeyFormat().getParams().getIvSize());
assertTrue(format.hasHmacKeyFormat());
assertTrue(format.getHmacKeyFormat().hasParams());
assertEquals(32, format.getHmacKeyFormat().getKeySize());
assertEquals(32, format.getHmacKeyFormat().getParams().getTagSize());
assertEquals(HashType.SHA256, format.getHmacKeyFormat().getParams().getHash());
}
Aggregations