use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class ProtoKeyTest method testProtoKey_keyDataREMOTE_shouldNotHaveSecret.
@Test
public void testProtoKey_keyDataREMOTE_shouldNotHaveSecret() throws GeneralSecurityException {
KeyTemplate kt = KeyTemplates.get("ED25519");
KeyData kd = KeyData.newBuilder().mergeFrom(Registry.newKeyData(kt)).setKeyMaterialType(KeyData.KeyMaterialType.REMOTE).build();
ProtoKey pk = new ProtoKey(kd, kt.getOutputPrefixType());
assertThat(pk.getProtoKey()).isEqualTo(kd);
assertThat(pk.getOutputPrefixType()).isEqualTo(kt.getOutputPrefixType());
assertThat(pk.hasSecret()).isFalse();
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class ProtoKeyTest method testProtoKey_keyDataASYMMETRICPRIVATE_shouldHaveSecret.
@Test
public void testProtoKey_keyDataASYMMETRICPRIVATE_shouldHaveSecret() throws GeneralSecurityException {
KeyTemplate kt = KeyTemplates.get("ED25519");
KeyData kd = Registry.newKeyData(kt);
ProtoKey pk = new ProtoKey(kd, kt.getOutputPrefixType());
assertThat(pk.getProtoKey()).isEqualTo(kd);
assertThat(pk.getOutputPrefixType()).isEqualTo(kt.getOutputPrefixType());
assertThat(pk.hasSecret()).isTrue();
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeyTemplateHandler method parseArguments.
@Override
public final int parseArguments(final Parameters params) throws CmdLineException {
String templateName = params.getParameter(0);
try {
KeyTemplate template = TinkeyKeyTemplates.get().get(templateName);
// If cannot find the template in Tinkey, look it up in the main registry
if (template == null) {
template = KeyTemplates.get(templateName);
}
setter.addValue(template);
return 1;
} catch (GeneralSecurityException ex) {
throw new CmdLineException(owner, ex.getMessage(), ex);
}
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class AesGcmKeyManagerTest method testRawAes128GcmTemplate.
@Test
public void testRawAes128GcmTemplate() throws Exception {
KeyTemplate template = AesGcmKeyManager.rawAes128GcmTemplate();
assertEquals(new AesGcmKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
AesGcmKeyFormat format = AesGcmKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class AesGcmKeyManagerTest method testAes128GcmTemplate.
@Test
public void testAes128GcmTemplate() throws Exception {
KeyTemplate template = AesGcmKeyManager.aes128GcmTemplate();
assertEquals(new AesGcmKeyManager().getKeyType(), template.getTypeUrl());
assertEquals(KeyTemplate.OutputPrefixType.TINK, template.getOutputPrefixType());
AesGcmKeyFormat format = AesGcmKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
assertEquals(16, format.getKeySize());
}
Aggregations