gpt4 book ai didi

c# - 尝试连接时,Azure Vault 中的 GetSecret 抛出 NullReferenceException

转载 作者:行者123 更新时间:2023-12-03 00:59:22 25 4
gpt4 key购买 nike

我有以下问题:

我正在尝试使用证书凭据连接到 Azure Vault。

当尝试读取 secret 时,我收到带有内部 NullReferenceExceptionAuthenticationFailedException

为了简洁起见,我仅包含 NullReferenceException 的堆栈跟踪:

This exception was originally thrown at this call stack:
Azure.Identity.AadIdentityClient.CreateClientAssertionJWT(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2)
Azure.Identity.AadIdentityClient.CreateClientCertificateAuthRequest(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2, string[])
Azure.Identity.AadIdentityClient.Authenticate(string, string, System.Security.Cryptography.X509Certificates.X509Certificate2, string[], System.Threading.CancellationToken)
Azure.Identity.ClientCertificateCredential.GetToken(Azure.Core.TokenRequestContext, System.Threading.CancellationToken)

代码:

            string keyVaultUrl = "https://somevault.vault.azure.net/";
var clientId = "<Application (client) ID>";
var tenantId = "<Directory (tenant) ID>";
X509Certificate2 clientCertificate = new X509Certificate2(@"someCerFile.cer");
ClientCertificateCredential certificateCreadential = new ClientCertificateCredential(tenantId, clientId, clientCertificate);
var client = new SecretClient(new Uri(keyVaultUrl), certificateCreadential);
var secret = client.GetSecret("Password"); //This line throws the exception

保险柜配置是根据此处概述的步骤完成的:

https://learn.microsoft.com/en-us/azure/key-vault/general/authentication

有什么想法吗?

最佳答案

不幸的是,异常并没有多大帮助。但是,我认为这里的问题是您需要为 X509Certificate2 提供私钥,以便 ClientCertificateCredential 可以签署客户端断言。 .cer 文件只是证书的公共(public)部分。您需要提供一个 .pfx 文件,其中还包含证书和私钥。

关于c# - 尝试连接时,Azure Vault 中的 GetSecret 抛出 NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63156583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com