我正在使用以下方法从x509 Store
获得证书private X509Certificate GetCert(string certThumbPrint)
{
var certStore = new X509Store(StoreName.My, StoreLocation.LocalMachine);
certStore.Open(OpenFlags.ReadOnly);
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, certThumbPrint.Trim(), false);
certStore.Close();
// Check to see if our certificate was added to the collection. If no, throw an error, if yes, create a certificate using it.
if (0 == certCollection.Count || certCollection.Count == null)
{
throw new ApiException(string.Format("Error: Admin Service Client : No certificate found containing thumbprint {0}",certThumbPrint), ApiLogCategory.Configuration, ErrorCodes.AdminServiceClient);
}
var cert = new X509Certificate(certCollection[0].RawData, string.Empty, X509KeyStorageFlags.MachineKeySet);
return cert;
}
我正在遇到错误,因此我尝试调试并发现该应用程序无法打开X509商店。在这种情况下我该怎么办。
它看起来像是一个相关的问题。
您的证书是在个人商店安装的吗?
如果是这样,请右键单击证书=>所有任务=>管理私有键=>添加IIS AppPool AppPoolName并授予它完整控制
如果您在与应用程序池身份不同的帐户下运行应用程序池,则该用户。