DEV Community

Santhosh Thomas
Santhosh Thomas

Posted on

5 3

How To Store Certificate (.pem) in Azure Keyvault using Secrets and fetch values from secrets into pem file using python

Convert .pem Certificate file into base64 using certutil

certutil -encode filename.cer newfilename.cer
Enter fullscreen mode Exit fullscreen mode
  1. Go to azure portal

  2. Select ketvault service

  3. Create a new keyvault

  4. Select secrets from setting on sidepanel

  5. Create a new secret

  6. Copy paste base 64 into secret value and save it

### Python code to fetch certificate value from keyvault and store into a pem file

from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
credentials = DefaultAzureCredential()
secret_client = SecretClient(vault_url=key_vault_url, credential=credentials)
cert_value =  secret_client.get_secret("Certificate").value

with open('certificate.pem','w') as fopen:
        fopen.write(base64.b64decode(cert_value).decode())
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay