我需要从azure函数应用程序调用REST,这需要一个客户端证书。我遵循了这个How to manage signed certificates with Azure Function V2并做了以下步骤:-
1)我已经将我的私钥证书(.PFX)上传到了私钥证书下的TLS/SSL设置中。
(2)在配置/应用程序设置下为
WEBSITE_LOAD_CERTIFICATES:“我的证书指纹”
然后,我尝试使用以下方法访问代码中的证书
使用系统;使用System.Security.Cryptography.X509Certificates;
...
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
certStore.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = certStore.Certificates.Find(
X509FindType.FindByThumbprint,
// Replace below with your certificate's thumbprint
"000000000000000000000000000000000000000",
false);
// Get the first cert with the thumbprint
if (certCollection.Count > 0)
{
X509Certificate2 cert = certCollection[0];
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
certStore.Close();
...我没有得到任何证明。我做错了什么?如果我上传一个公共证书(.cer),我可以访问证书,但它没有私钥,所以我无法调用服务。
发布于 2020-11-24 06:03:31
首先,请检查是否将Thumbprint复制到您的函数应用程序设置WEBSITE_LOAD_CERTIFICATES中(在下面的屏幕快照中)。

然后,请在代码中使用cert的其他字段进行测试,因为有时证书没有FriendlyName。我在我身边进行测试,它没有显示出FriendlyName的任何内容。然后我用Issuer进行测试,它运行得很好。(注意,我使用log.LogInformation(cert.Issuer);而不是Console.WriteLine(cert.Issuer);,因为我发现Console.WriteLine什么都没有显示)

https://stackoverflow.com/questions/64979861
复制相似问题