简体   繁体   English

使用 Azure.Security.KeyVault 通过 SecretId / SecretIdentifier 而不是 Microsoft.Azure.KeyVault 检索证书(PFXcontent)

[英]Using Azure.Security.KeyVault to retrieve certificate (PFXcontent) via SecretId / SecretIdentifier instead of Microsoft.Azure.KeyVault

Just wondering how you would achieve the same using the new Azure.Security.KeyVault libraries:只是想知道如何使用新的Azure.Security.KeyVault库来实现相同的目标:

  1. Azure.Security.KeyVault.Certificates

https://docs.microsoft.com/en-us/dotnet/api/overview/azure/security.keyvault.certificates-readme?view=azure-dotnet https://docs.microsoft.com/en-us/dotnet/api/overview/azure/security.keyvault.certificates-readme?view=azure-dotnet

  1. Azure.Security.KeyVault.Secrets

https://docs.microsoft.com/en-us/dotnet/api/overview/azure/security.keyvault.secrets-readme?view=azure-dotnet#retrieve-a-secret https://docs.microsoft.com/en-us/dotnet/api/overview/azure/security.keyvault.secrets-readme?view=azure-dotnet#retrieve-a-secret

Particularly with regards to getting the PFX content from the certificate SecretId.特别是关于从证书 SecretId 获取 PFX 内容。 The new libraries don't seem to offer a way to get the Secret by SecretId or SecretIdentifier, only by name.新库似乎没有提供通过 SecretId 或 SecretIdentifier 获取 Secret 的方法,只能通过名称。

With the aim of matching what would have previously been done like this:为了匹配以前会这样做的事情:

var azureServiceTokenProvider = new AzureServiceTokenProvider();

var keyVaultClient = new KeyVaultClient(
                new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

CertificateBundle certificateBundle = await keyVaultClient.GetCertificateAsync(certificateIdentifier);

SecretBundle certificateWithPrivateKey = await keyVaultClient.GetSecretAsync(certificateBundle.SecretIdentifier.Identifier);

byte[] certificateWithPrivateKeyDecoded = Convert.FromBase64String(certificateWithPrivateKey.Value);

var certificate = new X509Certificate2(certificateWithPrivateKeyDecoded, (string)null);

return certificate;

Yes, the method does not offer a way to get the Secret by SecretIdentifier, but it has a parameter version , see SecretClient.GetSecret(String, String, CancellationToken) .是的,该方法不提供通过 SecretIdentifier 获取 Secret 的方法,但它具有参数version ,请参阅SecretClient.GetSecret(String, String, CancellationToken)

In your case, if you have the certificateIdentifier , the secret name and version are included, they are the same as the certificate, just pass them to the method.在您的情况下,如果您有certificateIdentifier ,则包括secret nameversion ,它们与证书相同,只需将它们传递给方法即可。

在此处输入图像描述

var client = new SecretClient(vaultUri: new Uri(keyVaultUrl), credential: new DefaultAzureCredential());
KeyVaultSecret secret = client.GetSecret("secret-name","secret-version");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用来自 azure.security.keyvault 的新 keyvault 客户端进行签名 - How to sign using new keyvault client from azure.security.keyvault 生成 Azure KeyVault SecretIdentifier (Url) with Version - Generate Azure KeyVault SecretIdentifier (Url) with Version 使用 KeyVaultClient 在 Azure KeyVault 密钥上定义策略 - Define Policy on Azure KeyVault Key using KeyVaultClient 有没有办法将证书从 azure 密钥库导入 azure web 应用程序中的 Z303CB0EF5825EDB9082DAZ61? - Is there a way to import certificate from azure keyvault to azure web app in .NET? Azure.Identity.CredentialUnavailableException 使用 azure.Security.KeyVault.Certificates 从 AzureKeyVault 获取证书 - Azure.Identity.CredentialUnavailableException GetCertificate from AzureKeyVault using azure.Security.KeyVault.Certificates 使用 Fluent 限制对 Azure KeyVault 的访问 - Restrict access to Azure KeyVault using Fluent 从Azure KeyVault加载X509证书 - Loading X509Certificate from Azure KeyVault 仅使用计算机上安装的证书访问 Azure KeyVault 机密 - Accessing Azure KeyVault secrets only with a certificate installed on the machine 使用带有外部 Azure KeyVault (HSM) 密钥的 BouncyCastle 创建证书时签名无效 - Invalid signature when creating a certificate using BouncyCastle with an external Azure KeyVault (HSM) Key 从 ASP.NET 核心应用程序访问 Azure KeyVault 中的证书 - Accessing certificate in Azure KeyVault from ASP.NET Core app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM