use of com.google.crypto.tink.proto.KeyData 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();
}
use of com.google.crypto.tink.proto.KeyData 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);
}
use of com.google.crypto.tink.proto.KeyData 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();
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class JwtRsaSsaPkcs1SignKeyManagerTest method withCustomKid.
/* Create a new keyset handle with the "custom_kid" value set. */
private KeysetHandle withCustomKid(KeysetHandle keysetHandle, String customKid) throws Exception {
Keyset keyset = CleartextKeysetHandle.getKeyset(keysetHandle);
JwtRsaSsaPkcs1PrivateKey privateKey = JwtRsaSsaPkcs1PrivateKey.parseFrom(keyset.getKey(0).getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
JwtRsaSsaPkcs1PublicKey publicKeyWithKid = privateKey.getPublicKey().toBuilder().setCustomKid(CustomKid.newBuilder().setValue(customKid).build()).build();
JwtRsaSsaPkcs1PrivateKey privateKeyWithKid = privateKey.toBuilder().setPublicKey(publicKeyWithKid).build();
KeyData keyDataWithKid = keyset.getKey(0).getKeyData().toBuilder().setValue(privateKeyWithKid.toByteString()).build();
Keyset.Key keyWithKid = keyset.getKey(0).toBuilder().setKeyData(keyDataWithKid).build();
return CleartextKeysetHandle.fromKeyset(keyset.toBuilder().setKey(0, keyWithKid).build());
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPublicKeyData_shouldWork.
@Test
public void testGetPublicKeyData_shouldWork() throws Exception {
KeyData privateKeyData = Registry.newKeyData(SignatureKeyTemplates.ECDSA_P256);
KeyData publicKeyData = Registry.getPublicKeyData(privateKeyData.getTypeUrl(), privateKeyData.getValue());
PublicKeyVerify verifier = Registry.<PublicKeyVerify>getPrimitive(publicKeyData);
PublicKeySign signer = Registry.<PublicKeySign>getPrimitive(privateKeyData);
byte[] message = "Nice test message".getBytes(UTF_8);
verifier.verify(signer.sign(message), message);
}
Aggregations