use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class JsonKeysetReaderTest method testReadEncrypted_singleKey_shouldWork.
@Test
public void testReadEncrypted_singleKey_shouldWork() throws Exception {
KeyTemplate masterKeyTemplate = AeadKeyTemplates.AES128_EAX;
Aead masterKey = Registry.getPrimitive(Registry.newKeyData(masterKeyTemplate));
KeysetHandle handle1 = KeysetHandle.generateNew(MacKeyTemplates.HMAC_SHA256_128BITTAG);
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 CleartextKeysetHandleTest method testParse.
@Test
public void testParse() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetHandle handle = KeysetHandle.generateNew(template);
Keyset keyset = handle.getKeyset();
handle = CleartextKeysetHandle.parseFrom(keyset.toByteArray());
assertEquals(keyset, handle.getKeyset());
try {
Mac unused = MacFactory.getPrimitive(handle);
} catch (GeneralSecurityException e) {
fail("instantiation should succeed: " + e.toString());
}
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class CleartextKeysetHandleTest method testRead.
@Test
public void testRead() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetManager manager = KeysetManager.withEmptyKeyset().rotate(template);
Keyset keyset1 = manager.getKeysetHandle().getKeyset();
KeysetHandle handle1 = CleartextKeysetHandle.read(BinaryKeysetReader.withBytes(keyset1.toByteArray()));
assertEquals(keyset1, handle1.getKeyset());
KeysetHandle handle2 = KeysetHandle.generateNew(template);
Keyset keyset2 = handle2.getKeyset();
assertEquals(1, keyset2.getKeyCount());
Keyset.Key key2 = keyset2.getKey(0);
assertEquals(keyset2.getPrimaryKeyId(), key2.getKeyId());
assertEquals(template.getTypeUrl(), key2.getKeyData().getTypeUrl());
try {
Mac unused = MacFactory.getPrimitive(handle2);
} catch (GeneralSecurityException e) {
fail("instantiation should succeed: " + e.toString());
}
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class KeysetManagerTest method testAdd_shouldAddNewKey.
@Test
public void testAdd_shouldAddNewKey() throws Exception {
// Create a keyset that contains a single HmacKey.
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
Keyset keyset = KeysetManager.withEmptyKeyset().add(template).getKeysetHandle().getKeyset();
assertThat(keyset.getKeyCount()).isEqualTo(1);
assertThat(keyset.getPrimaryKeyId()).isEqualTo(0);
TestUtil.assertHmacKey(template, keyset.getKey(0));
}
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);
}
Aggregations