use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testGetPrimitive_legacy_aesGcm_shouldWork.
@Test
public void testGetPrimitive_legacy_aesGcm_shouldWork() throws Exception {
AesEaxKey aesEaxKey = (AesEaxKey) Registry.newKey(AesEaxKeyManager.aes128EaxTemplate().getProto());
KeyData aesEaxKeyData = Registry.newKeyData(AesEaxKeyManager.aes128EaxTemplate().getProto());
Aead aead = Registry.getPrimitive(aesEaxKeyData);
assertThat(aesEaxKey.getKeyValue().size()).isEqualTo(16);
assertThat(aesEaxKeyData.getTypeUrl()).isEqualTo(AeadConfig.AES_EAX_TYPE_URL);
// This might break when we add native implementations.
assertThat(aead.getClass()).isEqualTo(AesEaxJce.class);
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class RegistryTest method testDeriveKey_succeeds.
@Test
public void testDeriveKey_succeeds() throws Exception {
Registry.reset();
Registry.registerKeyManager(new TestKeyTypeManager(), true);
AesGcmKeyFormat format = AesGcmKeyFormat.newBuilder().setKeySize(16).build();
com.google.crypto.tink.proto.KeyTemplate template = com.google.crypto.tink.proto.KeyTemplate.newBuilder().setValue(format.toByteString()).setTypeUrl(new TestKeyTypeManager().getKeyType()).setOutputPrefixType(OutputPrefixType.TINK).build();
byte[] keyMaterial = Random.randBytes(100);
KeyData keyData = Registry.deriveKey(template, new ByteArrayInputStream(keyMaterial));
assertThat(keyData.getKeyMaterialType()).isEqualTo(new TestKeyTypeManager().keyMaterialType());
assertThat(keyData.getTypeUrl()).isEqualTo(new TestKeyTypeManager().getKeyType());
AesGcmKey key = AesGcmKey.parseFrom(keyData.getValue(), ExtensionRegistryLite.getEmptyRegistry());
for (int i = 0; i < 16; ++i) {
assertThat(key.getKeyValue().byteAt(i)).isEqualTo(keyMaterial[i]);
}
}
use of com.google.crypto.tink.proto.KeyData in project tink by google.
the class JwtHmacKeyManagerTest 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);
JwtHmacKey hmacKey = JwtHmacKey.parseFrom(keyset.getKey(0).getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
JwtHmacKey hmacKeyWithKid = hmacKey.toBuilder().setCustomKid(CustomKid.newBuilder().setValue(customKid).build()).build();
KeyData keyDataWithKid = keyset.getKey(0).getKeyData().toBuilder().setValue(hmacKeyWithKid.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 JwtEcdsaSignKeyManagerTest 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);
JwtEcdsaPrivateKey privateKey = JwtEcdsaPrivateKey.parseFrom(keyset.getKey(0).getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
JwtEcdsaPublicKey publicKeyWithKid = privateKey.getPublicKey().toBuilder().setCustomKid(CustomKid.newBuilder().setValue(customKid).build()).build();
JwtEcdsaPrivateKey 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 JwtRsaSsaPssSignKeyManagerTest 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);
JwtRsaSsaPssPrivateKey privateKey = JwtRsaSsaPssPrivateKey.parseFrom(keyset.getKey(0).getKeyData().getValue(), ExtensionRegistryLite.getEmptyRegistry());
JwtRsaSsaPssPublicKey publicKeyWithKid = privateKey.getPublicKey().toBuilder().setCustomKid(CustomKid.newBuilder().setValue(customKid).build()).build();
JwtRsaSsaPssPrivateKey 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());
}
Aggregations