Search in sources :

Example 31 with KeyTemplate

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();
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 32 with KeyTemplate

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();
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 33 with KeyTemplate

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);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) KeyTemplate(com.google.crypto.tink.KeyTemplate) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 34 with KeyTemplate

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());
}
Also used : AesGcmKeyFormat(com.google.crypto.tink.proto.AesGcmKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 35 with KeyTemplate

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());
}
Also used : AesGcmKeyFormat(com.google.crypto.tink.proto.AesGcmKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

KeyTemplate (com.google.crypto.tink.KeyTemplate)143 Test (org.junit.Test)135 KeysetHandle (com.google.crypto.tink.KeysetHandle)56 ByteString (com.google.protobuf.ByteString)39 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)37 KeyData (com.google.crypto.tink.proto.KeyData)16 Keyset (com.google.crypto.tink.proto.Keyset)12 JsonObject (com.google.gson.JsonObject)8 KeysetManager (com.google.crypto.tink.KeysetManager)7 BigInteger (java.math.BigInteger)7 Instant (java.time.Instant)7 Aead (com.google.crypto.tink.Aead)6 Enums (com.google.crypto.tink.subtle.Enums)6 Clock (java.time.Clock)6 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)5 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)4 AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)4 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)4 AesGcmSivKeyFormat (com.google.crypto.tink.proto.AesGcmSivKeyFormat)4 EciesAeadHkdfKeyFormat (com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat)4