我有一个 Azure Functions,它不断向我返回“无法识别提供给包的凭据”。证书(pfx 格式)已作为私钥证书上传到 Azure - 请参阅下图 - 并且状态良好,我可以读取其中的 3 个证书。
我还设置了 appSettings WEBSITE_LOAD_USER_PROFILE=1 和 WEBSITE_LOAD_CERTIFICATES=thumbprints 但没有运气。这是我的函数应用程序的应用程序设置。
这是我在处理证书时使用的代码。我正在关注 Microsoft 的官方文档 - https://learn.microsoft.com/da-dk/azure/app-service/configure-ssl-certificate-in-code#load-certificate-in-windows-apps
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
string certThumbprint = "certThumbprint";
bool validOnly = false;
using (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
certThumbprint,
validOnly);
// Get the first cert with the thumbprint
X509Certificate2 cert = certCollection.OfType<X509Certificate>().FirstOrDefault();
if (cert is null)
throw new Exception($"Certificate with thumbprint {certThumbprint} was not found");
// Use certificate
Console.WriteLine(cert.FriendlyName);
}
最佳答案
总结作者提供的评论,供其他社区引用:
该问题是由以下代码行引起的:X509Certificate2 cert = certCollection.OfType<X509Certificate>().FirstOrDefault();
将代码行更改为:if (certCollection.Count > 0) { return certCollection[0]; }
,然后就可以了。
关于c# - Azure Functions 不断返回 'The credentials supplied to the package were not recognized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66439008/