Microsoft Azure Developer Associate AZ-204 Practice Question
Your ASP.NET Core web API uses an X.509 certificate whose private key is stored in an Azure Key Vault certificate named "SigningCert". The API must load the certificate at startup so that it can create an X509Certificate2 object that includes the private key.
You add the Azure.Identity package and create the following code:
var vaultUri = new Uri(Environment.GetEnvironmentVariable("KEYVAULT_URI"));
var credential = new DefaultAzureCredential();
// TODO: add code here to load the certificate including the private key
Which code fragment should you use to meet the requirement?
var client = new KeyClient(vaultUri, credential); var key = await client.GetKeyAsync("SigningCert"); var cert = new X509Certificate2(key.Value.Key.N);
var client = new CertificateClient(vaultUri, credential); var pfx = await client.DownloadCertificateAsync("SigningCert"); var cert = new X509Certificate2(pfx.Value);
var client = new SecretClient(vaultUri, credential); var secret = await client.GetSecretAsync("SigningCert"); var cert = new X509Certificate2(Convert.FromBase64String(secret.Value.Value));
var client = new SecretClient(vaultUri, credential); var cert = await client.DownloadCertificateAsync("SigningCert");