Search in sources :

Example 71 with KeyTemplate

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

the class AesGcmHkdfStreamingKeyManagerTest method testAes128GcmHkdf4KBTemplate.

@Test
public void testAes128GcmHkdf4KBTemplate() throws Exception {
    KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes128GcmHkdf4KBTemplate();
    assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(16);
    assertThat(format.getParams().getDerivedKeySize()).isEqualTo(16);
    assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 72 with KeyTemplate

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

the class AesGcmHkdfStreamingKeyManagerTest method testAes256GcmHkdf4KBTemplate.

@Test
public void testAes256GcmHkdf4KBTemplate() throws Exception {
    KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes256GcmHkdf4KBTemplate();
    assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(32);
    assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
    assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
Also used : AesGcmHkdfStreamingKeyFormat(com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 73 with KeyTemplate

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

the class KeyHandleTest method createFromKey_keyDataUnknown_shouldHaveSecret.

@Test
public void createFromKey_keyDataUnknown_shouldHaveSecret() throws Exception {
    KeyTemplate kt = KeyTemplates.get("ED25519");
    KeyData kd = KeyData.newBuilder().mergeFrom(Registry.newKeyData(kt)).setKeyMaterialType(KeyData.KeyMaterialType.UNKNOWN_KEYMATERIAL).build();
    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 74 with KeyTemplate

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

the class KeyHandleTest method generateNew_generatesDifferentKeys.

@Test
public void generateNew_generatesDifferentKeys() throws Exception {
    KeyTemplate template = KeyTemplates.get("AES128_EAX");
    Set<String> keys = new TreeSet<>();
    int numKeys = 2;
    for (int j = 0; j < numKeys; j++) {
        KeyHandle handle = KeyHandle.generateNew(template);
        ProtoKey protoKey = (ProtoKey) handle.getKey(SecretKeyAccess.insecureSecretAccess());
        KeyData keyData = protoKey.getProtoKey();
        AesEaxKey aesEaxKey = AesEaxKey.parseFrom(keyData.getValue(), ExtensionRegistryLite.getEmptyRegistry());
        keys.add(aesEaxKey.getKeyValue().toStringUtf8());
    }
    assertThat(keys).hasSize(numKeys);
}
Also used : AesEaxKey(com.google.crypto.tink.proto.AesEaxKey) ProtoKey(com.google.crypto.tink.tinkkey.internal.ProtoKey) TreeSet(java.util.TreeSet) ByteString(com.google.protobuf.ByteString) KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 75 with KeyTemplate

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

the class KeyHandleTest method createFromKey_keyDataAsymmetricPrivate_shouldHaveSecret.

@Test
public void createFromKey_keyDataAsymmetricPrivate_shouldHaveSecret() throws Exception {
    KeyTemplate kt = KeyTemplates.get("ED25519");
    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)

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