tink
tink copied to clipboard
How to use one of the ENABLED keyId from multi key keySet file?
if I have a multiple active keys in a keyset, how do I specify which KeyId I want to use to encrypt using Aead API?
{
"primaryKeyId": 1268760993,
"key": [
{
"keyData": {
"typeUrl": "type.googleapis.com/google.crypto.tink.AesGcmKey",
"value": "aaaaaa",
"keyMaterialType": "SYMMETRIC"
},
"status": "ENABLED",
"keyId": 1268760993,
"outputPrefixType": "TINK"
},
{
"keyData": {
"typeUrl": "type.googleapis.com/google.crypto.tink.AesGcmKey",
"value": "bbbbb",
"keyMaterialType": "SYMMETRIC"
},
"status": "ENABLED",
"keyId": 851085696,
"outputPrefixType": "TINK"
}
]
}
Hi @xmlking sorry for not replying earlier. One way to do so is for example in C++ using the KeysetManager
API; to use a key with ID keyId
:
- Call
KeysetManager::SetKeyId(keyId)
- Get a
KeysetManager::GetKeysetHandle()
- Get a (wrapped) primitive with
KeysetHandle::GetPrimitive()
The wrapped primitive (in this case AeadSetWrapper
) will encrypt with the primary key, and decrypt with the key whose ID is set as a prefix of the ciphertext.
I am going to close this issue. Feel free to reopen it if you have further questions!