Export App Service Certificate and set up a password

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.

This blog will guide how to export the App Service Certificate from Azure Portal and set up a password for the certificate in Windows and export it with password by using PowerShell.

 

When we create App Service Certificate (Add and manage TLS/SSL certificates - Azure App Service | Microsoft Learn) in Azure Portal, sometime we are not using it in the App Service but use it for Azure VM or on-prem VM. Moreover, we will use it in some Azure resources (such as upload the certificate to Azure Application Gateway).

 

However, after you export the App Service Certificate from Azure Portal, when you are going to upload it to Azure Application Gateway or use it in the Azure VM or on-prem VM, you would find out sometimes it would need the "password". But you don't know what the password is for the certificate. This is because when we export App Service Certificate, it is without password by default so we need to set it up manually by ourselves.

 

In this article, we will show you how to export the App Service Certificate and set up the password for certificate in Windows:

Export the App Service Certificate in Azure Portal and set up the password in Windows

  1. Go to your App Service Certificate and click "Export Certificate" -> "Open Key Vault Secret"

Joe_Chen_0-1675305226838.png

  1. Click the current version of certificate

Joe_Chen_0-1675305545457.png

  1. Click "Download as a certificate"

Joe_Chen_2-1675305226850.png

  1. Right click on the download .pfx certificate and click "Install PFX"

Joe_Chen_3-1675305226854.png

  1. Select "Current User"

Joe_Chen_4-1675305226859.png

  1. Make sure that select the correct .pfx file

Joe_Chen_5-1675305226863.png

  1. Keep the password empty and check the "Mark this key as exportable. This will allow you to backup or transport your keys at a latter time" checkbox

Joe_Chen_6-1675305226868.png

  1. Select "Place all certificates in the following store" and Choose "Personal" for Certicate store

Joe_Chen_7-1675305226872.png

  1. Click "Finish"
  2. Open Certificate Manager by searching "certmgr.msc" in Windows

Joe_Chen_8-1675305226903.png

  1. Select "Certificates - Current User" -> "Personal" -> "Certificate". Then right click on the target certificate and select "All Tasks" -> "Exports…"

Joe_Chen_9-1675305226913.png

  1. Choose "Yes, export the private key"

Joe_Chen_10-1675305226916.png

  1. Choose "Personal Information Exchange - PKCS #12 (.PFX)" and make sure check the "Include all certificates in the certification path if possible" and "Enable certificate privacy"

Joe_Chen_11-1675305226922.png

  1. Select the "Password" and enter the password

Joe_Chen_12-1675305226925.png

  1. Give a filename to save this certificate

Joe_Chen_13-1675305226927.png

  1. Click "Finish"

Export the App Service Certificate with the password by PowerShell

You could also use the PowerShell simply to export it by following script:

 

#Connect to Azure and select subscription Login-AzureRmAccount Select-AzureRMSubscription -SubscriptionName "<name of subscription containing keyvault>" #Obtain the secret from keyvault $vaultName = '<name of Keyvault>' $secretName = '<name of secret containing certificate>' $certString = Get-AzureKeyVaultSecret -VaultName $vaultName -Name $secretName #Create a PFX from the secret and write to disk $kvSecretBytes = [System.Convert]::FromBase64String($certString.SecretValueText) $certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection $certCollection.Import($kvSecretBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable) $password = '<required password for PFX>' $protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password) $pfxPath = "C:\temp\$secretName.pfx" [System.IO.File]::WriteAllBytes($pfxPath, $protectedCertificateBytes)

 

 

Congratulation, after these steps, now you will get a certificate with password! At last, would like add a kind reminder below:

Joe_Chen_1-1675305587222.png

Hope this article is helpful for you, thank you for reading :)

 

Reference:

Azure: Exporting App Service Certificates - TechNet Articles - United States (English) - TechNet Wiki (microsoft.com)

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.