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());
}
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());
}
Aggregations