use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class HmacKeyManagerTest method testNewKeyCorruptedFormat.
@Test
public void testNewKeyCorruptedFormat() throws Exception {
HmacKeyManager keyManager = new HmacKeyManager();
ByteString serialized = ByteString.copyFrom(new byte[128]);
KeyTemplate keyTemplate = KeyTemplate.newBuilder().setTypeUrl(HmacKeyManager.TYPE_URL).setValue(serialized).build();
try {
keyManager.newKey(serialized);
fail("Corrupted format, should have thrown exception");
} catch (GeneralSecurityException expected) {
// Expected
}
try {
keyManager.newKeyData(keyTemplate.getValue());
fail("Corrupted format, should have thrown exception");
} catch (GeneralSecurityException expected) {
// Expected
}
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class DeterministicAeadKeyTemplatesTest method testAES256_SIV.
@Test
public void testAES256_SIV() throws Exception {
KeyTemplate template = DeterministicAeadKeyTemplates.AES256_SIV;
assertEquals(AesSivKeyManager.TYPE_URL, template.getTypeUrl());
assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
AesSivKeyFormat format = AesSivKeyFormat.parseFrom(template.getValue());
assertEquals(64, format.getKeySize());
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class JsonKeysetReaderTest method testReadEncrypted_JsonKeysetWriter_shouldWork.
@Test
public void testReadEncrypted_JsonKeysetWriter_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.withBytes(outputStream.toByteArray()), masterKey);
assertKeysetHandle(handle1, handle2);
}
use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.
the class KeysetManagerTest method manipulateKeyset.
private void manipulateKeyset(KeysetManager manager) {
try {
KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
manager.rotate(template).add(template).rotate(template).add(template);
} catch (GeneralSecurityException e) {
fail("should not throw exception: " + e);
}
}
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);
}
Aggregations