Search in sources :

Example 76 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class KeyHandleTest method getKeyTemplate.

@Test
public void getKeyTemplate() throws Exception {
    KeyTemplate keyTemplate = KeyTemplates.get("ED25519_RAW");
    TinkKey key = new DummyTinkKey(/* hasSecret= */
    false, keyTemplate);
    KeyHandle keyHandle = KeyHandle.createFromKey(key, KeyAccess.publicAccess());
    KeyTemplate returnedKeyTemplate = keyHandle.getKeyTemplate();
    assertThat(returnedKeyTemplate.getValue()).isEqualTo(keyTemplate.getValue());
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 77 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class KeyHandleTest method createFromKey_keyDataSymmetric_shouldHaveSecret.

@Test
public void createFromKey_keyDataSymmetric_shouldHaveSecret() throws Exception {
    KeyTemplate kt = KeyTemplates.get("AES128_EAX");
    KeyData kd = Registry.newKeyData(kt);
    KeyHandle kh = KeyHandle.createFromKey(kd, kt.getOutputPrefixType());
    assertThat(kh.hasSecret()).isTrue();
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 78 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class ProtoKeyTest method testProtoKey_keyDataSYMMETRIC_shouldHaveSecret.

@Test
public void testProtoKey_keyDataSYMMETRIC_shouldHaveSecret() throws GeneralSecurityException {
    KeyTemplate kt = KeyTemplates.get("AES128_EAX");
    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 79 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class ProtoKeyTest method testGetKeyTemplate_shouldThrow.

@Test
public void testGetKeyTemplate_shouldThrow() throws GeneralSecurityException {
    KeyTemplate kt = AesEaxKeyManager.aes128EaxTemplate();
    KeyData kd = Registry.newKeyData(kt);
    ProtoKey pk = new ProtoKey(kd, kt.getOutputPrefixType());
    assertThrows(UnsupportedOperationException.class, pk::getKeyTemplate);
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 80 with KeyTemplate

use of com.google.crypto.tink.KeyTemplate in project tink by google.

the class ProtoKeyTest method testProtoKey_keyDataASYMMETRICPUBLIC_shouldNotHaveSecret.

@Test
public void testProtoKey_keyDataASYMMETRICPUBLIC_shouldNotHaveSecret() throws GeneralSecurityException {
    KeyTemplate kt = KeyTemplates.get("ED25519");
    KeyData kd = Registry.getPublicKeyData(kt.getTypeUrl(), Registry.newKeyData(kt).getValue());
    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)

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