Upload procedure to the key vault storage depends on a certificate type.
Import of the *.pfx certificates
- The certificates with extension *.pfx can be uploaded to the Azure Key Vault using a PowerShell-script.
Connect-AzAccount
$pfxFilePath = '<Localpath>'
$pwd = ''
$secretName = '<name>'
$keyVaultName = '<keyvault>'
$collection = New-ObjectSystem.Security.Cryptography.X509Certificates.X509Certificate2Collection
$collection.Import($pfxFilePath, $pwd,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pkcs12ContentType =[System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12
$clearBytes = $collection.Export($pkcs12ContentType)
$fileContentEncoded = [System.Convert]::ToBase64String($clearBytes)
$secret = ConvertTo-SecureString -String $fileContentEncoded -AsPlainText –Force
$secretContentType = 'application/x-pkcs12'
Set-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName -SecretValue $Secret -ContentType $secretContentType
Where:
<Localpath> - local path to the file with certicate, e.g. C:\<smth>.pfx
<name> - name of the certificate, e.g. <smth>
<keyvault> - name of the Key vault storage
If password is required, add it to the tag $pwd
- Set a tag for the certificate uploaded to the Azure Key vault.
- In Microsoft Azure portal, click the "Dashboard" button and select the appropriate Key vault to open it.
- Click on the "Secrets" tile.
- Find an appropriate secret by the certificate name and open it.
- Open the "Tags" tab.
- Set Tag name = "type" and Tag value = "certificate".
Note: Tag name and Tag value must be filled in without quotes and in lowercase.
- Click the OK button and save the updated secret.
Import of the other certificates
- Click the "Dashboard" button on the left panel to see the key vault created earlier.
- Select the appropriate Key vault to open it. The "Overview" tab shows essential parameters of the key vault storage, including a "DNS name".
Note: The DNS Name is a mandatory parameter for integration with the key vault, therefore it should be specified in the application, and referred in "Setting up Azure Key Vault Client" as <Key Vault URL> parameter.
- Click on the "Secrets" tile.
- Click the "Generate/Import" button on the "Secrets" page to add a new certificate to the key vault storage. On the right side of the page, you should define the certificate parameters:
- Select the "Manual" value in the "Upload options" field.
- Enter the certificate name in the "Name" field.
Note: The Secret Name is a mandatory parameter for integration with the key vault, therefore it should be specified in the application. It is referred in "Setting up Azure Key Vault Client" as <SecretName> parameter.
- Open a certificate for editing and copy all its content including the beginning and closing tags.
- Paste the copied content in the "Value" field.
- Enable the certificate.
- Press the "Create" button.
- It's possible to upload several versions of the certificate and manage them in the key vault storage. If you need to upload a new version for an existing certificate, then select an appropriate certificate and click the "New version" button.
Note: The current version should be defined in application setup, and is referred to in "Setting up Azure Key Vault Client" as <SecretVersion> parameter.