use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class JsonKeysetReaderTest method testRead_singleKey_shouldWork.
@Test
public void testRead_singleKey_shouldWork() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetHandle handle1 = KeysetHandle.generateNew(template);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CleartextKeysetHandle.write(handle1, JsonKeysetWriter.withOutputStream(outputStream));
KeysetHandle handle2 = CleartextKeysetHandle.read(JsonKeysetReader.withInputStream(new ByteArrayInputStream(outputStream.toByteArray())));
assertKeysetHandle(handle1, handle2);
}
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 JsonKeysetReaderTest method testRead_jsonKeysetWriter_shouldWork.
@Test
public void testRead_jsonKeysetWriter_shouldWork() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
KeysetHandle handle1 = KeysetHandle.generateNew(template);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
CleartextKeysetHandle.write(handle1, JsonKeysetWriter.withOutputStream(outputStream));
KeysetHandle handle2 = CleartextKeysetHandle.read(JsonKeysetReader.withBytes(outputStream.toByteArray()));
assertKeysetHandle(handle1, handle2);
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class MacKeyTemplatesTest method hmacSha256_128BitTag.
@Test
public void hmacSha256_128BitTag() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
assertEquals(new HmacKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(32, format.getKeySize());
assertEquals(16, format.getParams().getTagSize());
assertEquals(HashType.SHA256, format.getParams().getHash());
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class MacKeyTemplatesTest method hmacSha256_256BitTag.
@Test
public void hmacSha256_256BitTag() throws Exception {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_256BITTAG;
assertEquals(new HmacKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(32, format.getKeySize());
assertEquals(32, format.getParams().getTagSize());
assertEquals(HashType.SHA256, format.getParams().getHash());
}
Aggregations