azureazure-keyvault

az keyvault key create error when creating symmetric key


I created an azure key vault (not a managed HSM service) and gave myself necessary permissions in azure portal to create and view keys. I wanted to create an AES-256 bit symmetric wrapping key (also known as key encryption key or KEK) with following azure CLI command:

az keyvault key create --name mywrappingkey --vault-name raghu-keyvault-wrap-exp --kty oct --size 256 --ops wrapKey --protection software

It fails with following error:

(BadParameter) Invalid kty value: oct
Code: BadParameter
Message: Invalid kty value: oct
Inner error: {
    "code": "KeyTypeNotSupported"
}

The following documentation says it should work: https://learn.microsoft.com/en-us/cli/azure/keyvault/key?view=azure-cli-latest#az-keyvault-key-create

I also tried using command (i.e. changed the --protection value to hsm):

az keyvault key create --name mywrappingkey --vault-name raghu-keyvault-wrap-exp --kty oct --size 256 --ops wrapKey --protection hsm

This time, it erred with following:

(BadParameter) Property  has invalid value

Code: BadParameter
Message: Property  has invalid value

Not sure what I am doing wrong here. Any ideas?


Solution

  • Note: Azure Key Vault does not support creating symmetric oct keys for wrapKey or decrypt operations directly via CLI.

    I got the same errors when creating symmetric key like below:

    az keyvault key create --name mywrappingkey --vault-name KvName --kty oct --size 256 --ops wrapKey --protection software
    

    enter image description here

    az keyvault key create --name mywrappingkey --vault-name KvName --kty oct --size 256 --ops wrapKey --protection hsm
    

    enter image description here

    Note: Azure Key Vault does not support symmetric (oct) keys for key wrapping operations. Only RSA or EC keys can be used for key wrapping (wrapKey), as AES symmetric KEKs cannot be created directly in Azure Key Vault.

    Reference:

    About keys - Azure Key Vault | Microsoft