【问题标题】:How to add certificate to X509Store from DSC (USB token)?如何从 DSC(USB 令牌)向 X509Store 添加证书?
【发布时间】:2017-04-18 09:33:36
【问题描述】:

我想向 X509Store 添加证书。我可以从 .pfx 文件添加证书。但我想从 DSC 令牌添加证书。如何做到这一点?

private static void InstallCertificate(string cerFileName)
{
    X509Certificate2 certificate = new X509Certificate2(cerFileName);
    X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

    store.Open(OpenFlags.ReadWrite);
    store.Add(certificate);
    store.Close();
}

这里 cerFileName 是 .pfx 文件的路径,但我没有 pfx 文件。我正在使用 DSC 令牌,所以我想将此证书添加到 X509Store。如何从 DSC 令牌添加证书?

【问题讨论】:

  • .NET 不知道这个 DSC 令牌是什么。您必须提供给X509Store 类证书对象。

标签: c# cryptography x509certificate x509 x509certificate2


【解决方案1】:

如果您的 DSC 令牌作为智能卡与 Windows 加密的其余部分一起使用,则 certutil 工具会有所帮助。该工具将从它认为是智能卡的任何设备上复制证书并注册私钥地址(位于智能卡上):

C:\Users\jbarton>certutil -scinfo -silent
The Microsoft Smart Card Resource Manager is running.
Current reader/card status:
Readers: 1
  0: Gemplus USB Smart Card Reader 0
--- Reader: Gemplus USB Smart Card Reader 0
--- Status: SCARD_STATE_PRESENT
--- Status: The card is available for use.
---   Card: Axalto Cryptoflex .NET
---    ATR:
        3b 16 96 41 73 74 72 69  64                        ;..Astrid


=======================================================
Analyzing card in reader: Gemplus USB Smart Card Reader 0

--------------===========================--------------
================ Certificate 0 ================
--- Reader: Gemplus USB Smart Card Reader 0
---   Card: Axalto Cryptoflex .NET
Provider = Microsoft Base Smart Card Crypto Provider
[SNIP bunch of less useful stuff]

CertContext[0][0]: dwInfoStatus=2 dwErrorStatus=1000041
  Issuer: CN=Mister Issuer, DC=Authority, DC=PKI
  NotBefore: 6/17/2013 4:26 PM
  NotAfter: 6/17/2014 4:26 PM
  Subject: CN=Jeremy Barton, OU=Users, DC=PKI
[more SNIPping]

--------------===========================--------------

使用 MMC 查看 CurrentUser\My 存储(certmgr.msc,Personal->Certificates)应显示该命令后来自智能卡的证书。出于某种原因,我昨天遇到了一个命令运行的案例,我在 MMC 中看到了它,但是一个打开 X509Store 的工具 找到新证书并使用它几秒钟没有找到它(2秒后没有工作,但在我检查电子邮件并再次尝试后工作)。

(是的,我知道我的测试智能卡很旧。但是,是的,certutil -scinfo 还是把它复制了过来,因为它仍在智能卡上,所以它对某人(我!)仍然有用。

不要忘记-silent,否则您会收到 PIN 提示。很多。

【讨论】:

    猜你喜欢
    • 2015-02-11
    • 2018-12-25
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    相关资源
    最近更新 更多