I have a Certificate in an Azure Key Vault that I would like to extract a private key from.
According to the Microsoft Docs:
When a Key Vault certificate is created, an addressable key and secret are also created with the same name. The Key Vault key allows key operations and the Key Vault secret allows retrieval of the certificate value as a secret.
However, I have been unsuccessful in extracting the private key from this. Here is an example of some python code I tried:
pem_data = get_secret('https://keyvault.azure.net/', 'x509-cert')
pem_data = '-----BEGIN CERTIFICATE----- ' + pem_data + ' -----END CERTIFICATE-----'
pem_data = pem_data.encode()
key = x509.load_pem_x509_certificate(pem_data, backend=default_backend())
private_key = key.private_key()
This however, will error saying it cannot load the certificate.