c# - 客户端应用程序发布但在本地工作时无法从商店中找到证书
问题描述
当我在本地运行它时,它成功地certificate
从 中找到smart card
,读取它并签署文档。
如果我在 a 上发布应用程序的这一部分,在using上client side
运行它,然后我运行整个并将其连接到它成功连接到它,但数量为0。IIS
https
application
localhost
client side app
certificates
不幸的是,因为它是client side
我只能使用logs
而不是debug
.
到目前为止,我已经确定没有certs
与thumbprint
. certificate
但是,再次在本地找到certificate
.thumprint
我试图将 , 更改X509Store
StoreName
为StoreName.Root
, StoreName.CertificationAuthority
,但它永远找不到cert
我正在寻找的。
public (InvoiceResult resultValue, X509Certificate2 cert) GetDefaultCertificateStoredOnTheCard()
{
var resultValue = InvoiceResult.Success;
using X509Store x509Store = new X509Store("MY", StoreLocation.CurrentUser);
X509Store store = x509Store;
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByTimeValid, DateTime.Now, true);
// by thumbprint, there is only one
certs = certs.Find(X509FindType.FindByThumbprint, Settings.Default.Thumbprint, true);
_log.TraceInformation($"Locations of certs in store after opening flags is {certs.Count}!");
if (certs.Count == 0)
{
resultValue = InvoiceResult.CannotFindSignature;
// throw new ArgumentException("Please insert smart card to obtain certificate.");
}
X509Certificate2 cert = certs[0];
if (cert.HasPrivateKey)
{
// software cert
_ = cert.PrivateKey as RSACryptoServiceProvider;
}
else
{
// certificate from smartcard
CspParameters csp = new CspParameters(1, "Microsoft Base Smart Card Crypto Provider")
{
Flags = CspProviderFlags.UseDefaultKeyContainer
};
_ = new RSACryptoServiceProvider(csp);
}
_log.TraceInformation($"GetDefaultCerticateStoredOnTheCard method gets values {cert}.");
_log.TraceInformation($"GetDefaultCerticateStoredOnTheCard method gets values {resultValue}.");
return (resultValue, cert);
}
任何建议将不胜感激。
解决方案
最有可能的是,运行您的应用程序的帐户没有从商店读取证书的权限。
在 MMC 中打开您的证书存储。右键单击证书并选择所有任务 > 管理私钥(注意:我的机器上安装了 Windows 7;在其他版本的 Windows 中可能会有所不同)。然后,您可以将读取权限分配给正确的用户帐户。
推荐阅读
- javascript - 如果 saveToGallery 为 false,则带有 MLKit 的 NativeScript 核心 CameraPlus 不起作用
- python - 如何在 IDLE 中显示呼叫提示?
- javascript - Angular 1.x 中的深度链接和路由
- python - Python - Http 服务器,如何发送 .ico 文件?
- java - 有没有办法在没有 getter 或 setter 的情况下制作推土机地图字段?(或者,什么映射器可以做到这一点?)
- c++ - 在 C++ 中,setter、getter 和构造函数有什么区别?
- canvas - 画布上的 Nativescript 视频不起作用
- bash - 在 bash 脚本中读取的 While 循环
- c++ - MS Visual Studio 2017 上的可变参数模板编译问题
- powershell - 循环混淆比较对象