Search in sources :

Example 11 with KeyHandle

use of com.google.crypto.tink.tinkkey.KeyHandle in project tink by google.

the class KeysetHandleTest method createFromKey_shouldWork.

@Test
public void createFromKey_shouldWork() throws Exception {
    KeyTemplate template = KeyTemplates.get("AES128_EAX");
    KeyHandle keyHandle = KeyHandle.generateNew(template);
    KeyAccess token = SecretKeyAccess.insecureSecretAccess();
    KeysetHandle handle = KeysetHandle.createFromKey(keyHandle, token);
    Keyset keyset = handle.getKeyset();
    expect.that(keyset.getKeyCount()).isEqualTo(1);
    Keyset.Key key = keyset.getKey(0);
    expect.that(keyset.getPrimaryKeyId()).isEqualTo(key.getKeyId());
    expect.that(key.getStatus()).isEqualTo(KeyStatusType.ENABLED);
    expect.that(key.getOutputPrefixType()).isEqualTo(OutputPrefixType.TINK);
    expect.that(key.hasKeyData()).isTrue();
    expect.that(key.getKeyData().getTypeUrl()).isEqualTo(template.getTypeUrl());
    AesEaxKeyFormat aesEaxKeyFormat = AesEaxKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    AesEaxKey aesEaxKey = AesEaxKey.parseFrom(key.getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
    expect.that(aesEaxKey.getKeyValue().size()).isEqualTo(aesEaxKeyFormat.getKeySize());
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) SecretKeyAccess(com.google.crypto.tink.tinkkey.SecretKeyAccess) KeyAccess(com.google.crypto.tink.tinkkey.KeyAccess) AesEaxKey(com.google.crypto.tink.proto.AesEaxKey) KeyHandle(com.google.crypto.tink.tinkkey.KeyHandle) AesEaxKeyFormat(com.google.crypto.tink.proto.AesEaxKeyFormat) Test(org.junit.Test)

Example 12 with KeyHandle

use of com.google.crypto.tink.tinkkey.KeyHandle in project tink by google.

the class KeysetHandleTest method primaryKey_shouldWork.

@Test
public void primaryKey_shouldWork() throws Exception {
    KeyTemplate kt1 = KeyTemplates.get("AES128_EAX");
    KeyTemplate kt2 = KeyTemplates.get("HMAC_SHA256_256BITTAG");
    KeysetHandle ksh = KeysetManager.withKeysetHandle(KeysetHandle.generateNew(kt1)).add(kt2).getKeysetHandle();
    KeyHandle kh = ksh.primaryKey();
    ProtoKey pk = (ProtoKey) kh.getKey(SecretKeyAccess.insecureSecretAccess());
    assertThat(pk.getProtoKey().getTypeUrl()).isEqualTo(kt1.getTypeUrl());
}
Also used : ProtoKey(com.google.crypto.tink.tinkkey.internal.ProtoKey) KeyHandle(com.google.crypto.tink.tinkkey.KeyHandle) Test(org.junit.Test)

Aggregations

KeyHandle (com.google.crypto.tink.tinkkey.KeyHandle)12 Test (org.junit.Test)11 Keyset (com.google.crypto.tink.proto.Keyset)7 KeyAccess (com.google.crypto.tink.tinkkey.KeyAccess)5 SecretKeyAccess (com.google.crypto.tink.tinkkey.SecretKeyAccess)5 ProtoKey (com.google.crypto.tink.tinkkey.internal.ProtoKey)5 AesGcmKey (com.google.crypto.tink.proto.AesGcmKey)4 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)4 Key (com.google.crypto.tink.proto.Keyset.Key)4 AesEaxKey (com.google.crypto.tink.proto.AesEaxKey)2 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)2 KeyData (com.google.crypto.tink.proto.KeyData)2 TinkKey (com.google.crypto.tink.tinkkey.TinkKey)2 Expect (com.google.common.truth.Expect)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AesEaxKeyManager (com.google.crypto.tink.aead.AesEaxKeyManager)1 TinkConfig (com.google.crypto.tink.config.TinkConfig)1 KeyStatusTypeProtoConverter (com.google.crypto.tink.internal.KeyStatusTypeProtoConverter)1 EcdsaPrivateKey (com.google.crypto.tink.proto.EcdsaPrivateKey)1 EncryptedKeyset (com.google.crypto.tink.proto.EncryptedKeyset)1