Search in sources :

Example 36 with KeyData

use of com.google.crypto.tink.proto.KeyData in project tink by google.

the class KeyHandleTest method createFromKey_keyDataRemote_shouldNotHaveSecret.

@Test
public void createFromKey_keyDataRemote_shouldNotHaveSecret() throws Exception {
    KeyTemplate kt = KeyTemplates.get("ED25519");
    KeyData kd = KeyData.newBuilder().mergeFrom(Registry.newKeyData(kt)).setKeyMaterialType(KeyData.KeyMaterialType.REMOTE).build();
    KeyHandle kh = KeyHandle.createFromKey(kd, kt.getOutputPrefixType());
    assertThat(kh.hasSecret()).isFalse();
}
Also used : KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 37 with KeyData

use of com.google.crypto.tink.proto.KeyData in project tink by google.

the class KeyHandleTest method generateNew_compareWith_createFromKeyViaProtoKey_shouldBeEqual.

@Test
public void generateNew_compareWith_createFromKeyViaProtoKey_shouldBeEqual() throws Exception {
    KeyTemplate template = KeyTemplates.get("AES128_EAX");
    KeyData keyData = Registry.newKeyData(template);
    ProtoKey protoKey = new ProtoKey(keyData, template.getOutputPrefixType());
    KeyHandle handle1 = KeyHandle.generateNew(template);
    KeyHandle handle2 = KeyHandle.createFromKey(protoKey, SecretKeyAccess.insecureSecretAccess());
    expect.that(handle1.getStatus()).isEqualTo(handle2.getStatus());
    ProtoKey outputProtoKey1 = (ProtoKey) handle1.getKey(SecretKeyAccess.insecureSecretAccess());
    ProtoKey outputProtoKey2 = (ProtoKey) handle2.getKey(SecretKeyAccess.insecureSecretAccess());
    expect.that(outputProtoKey1.getOutputPrefixType()).isEqualTo(outputProtoKey2.getOutputPrefixType());
    expect.that(handle1.hasSecret()).isEqualTo(handle2.hasSecret());
}
Also used : ProtoKey(com.google.crypto.tink.tinkkey.internal.ProtoKey) KeyTemplate(com.google.crypto.tink.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 38 with KeyData

use of com.google.crypto.tink.proto.KeyData in project tink by google.

the class ProtoKeyTest method testProtoKey_keyDataUNKNOWN_shouldHaveSecret.

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

use of com.google.crypto.tink.proto.KeyData 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 40 with KeyData

use of com.google.crypto.tink.proto.KeyData 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)

Aggregations

KeyData (com.google.crypto.tink.proto.KeyData)66 Test (org.junit.Test)55 Keyset (com.google.crypto.tink.proto.Keyset)17 KeyTemplate (com.google.crypto.tink.KeyTemplate)16 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)11 GeneralSecurityException (java.security.GeneralSecurityException)10 ByteString (com.google.protobuf.ByteString)9 TreeSet (java.util.TreeSet)9 AesEaxKey (com.google.crypto.tink.proto.AesEaxKey)7 KeysetReader (com.google.crypto.tink.KeysetReader)6 ProtoKey (com.google.crypto.tink.tinkkey.internal.ProtoKey)6 StringReader (java.io.StringReader)6 KeysetHandle (com.google.crypto.tink.KeysetHandle)5 RsaSsaPssPublicKey (com.google.crypto.tink.proto.RsaSsaPssPublicKey)5 BufferedReader (java.io.BufferedReader)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 DummyAead (com.google.crypto.tink.TestUtil.DummyAead)4 EcdsaPrivateKey (com.google.crypto.tink.proto.EcdsaPrivateKey)4 Ed25519PrivateKey (com.google.crypto.tink.proto.Ed25519PrivateKey)4 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)3