X509Store-如何列出USB密钥中的证书

X509Store-如何列出USB密钥中的证书,usb,x509certificate,digital-signature,x509,Usb,X509certificate,Digital Signature,X509,在将签署文档的web应用程序aspx/C中,如何列出位于用户USB密钥身份验证/签名密钥上的证书 这是我的密码: using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Web; using System.Web.UI; using System.Web.UI.We

在将签署文档的web应用程序aspx/C中,如何列出位于用户USB密钥身份验证/签名密钥上的证书

这是我的密码:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Security.Cryptography.X509Certificates;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  

namespace Signature1  
{  
    public partial class signature : System.Web.UI.Page  
    {  
        string strTxt = "Certificates : ";

        protected void Page_Load(object sender, EventArgs e)
        {
            X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

            store.Open(OpenFlags.ReadOnly);
            foreach (X509Certificate2 cert in store.Certificates)
            {
                strTxt += "\nDélivered to " + cert.SubjectName.Name + " by " + cert.IssuerName.Name;

            }
            store.Close();
            myTextbox.Text = strTxt ;

        }
    }
}
此代码在本地计算机调试模式下运行良好,但在应用程序服务器上发布时返回空列表。
感谢您的帮助。

如果您需要从位于服务器上的设备读取证书,请执行以下操作:

在应用服务器上,您的代码很可能在服务帐户下工作。在这种情况下,使用StoreLocation.CurrentUser参数引用的CurrentUser存储将为空

现在,它取决于硬件的驱动程序如何映射来自USB令牌的证书。如果它可以将证书映射到LocalMachine存储,那么您可以修改代码以从LocalMachine枚举证书。如果驱动程序只将它们映射到当前用户,那么您很可能需要在该用户帐户下运行代码。可以在Windows中使用或,这样您就可以只为一个线程切换到特定的用户帐户

另一种选择是,如果硬件供应商提供了相应的驱动程序DLL,并且您有权将其放入服务器系统,则可以通过PKCS11接口访问设备。在这种情况下,您以代码登录到硬件,而硬件并不关心用户。PKCS11接口与X509Store非常不同,需要使用第三方库,如我们的SecureBackbox。但在某些情况下,这似乎是唯一的选择

如果需要从远程客户端上的设备读取证书:

唯一的选择是有一个客户端模块,通常是Java小程序,可以访问设备。Java小程序可以在Windows上与PKCS11和Windows证书存储一起使用


缺点是Java小程序不能在移动平台上工作,在移动平台上,您唯一的选择是某种类型的客户端应用程序。到目前为止,这个问题没有很好的通用解决方案。

您的意思是,使用PKCS11接口,web应用程序可以访问客户端计算机上的LocalMachine商店吗?@MisterB。似乎我误读了您的问题很容易误读,因为您没有指定要读取连接的远程客户端系统上的证书。我会更新我的答案。