【问题标题】:Importing pfx/p12 file into smartcard c#将 pfx/p12 文件导入智能卡 c#
【发布时间】:2014-07-12 12:39:52
【问题描述】:

有没有办法以编程方式将.p12/pfx 文件导入智能卡?我知道它可以通过certutil 工作:

certutil -user -p "pw" -csp "csp" -importpfx path

我正在使用“Microsoft Base Smart Card Crypto Provider”

通过 certutil 它正在工作,因此我确信它也应该使用 c#(可能是 CRYPTOAPI)...我只是不想使用某种(启动 cmd 添加“导入字符串”):

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  
startInfo.FileName = "cmd.exe";            
startInfo.Arguments = strCmdText;           
process.StartInfo = startInfo;            
process.Start();

导入 pfx!

但我不知道这如何在 c# 中以编程方式工作。任何帮助将不胜感激。

【问题讨论】:

  • 取决于智能卡和中间层,无论你能找到什么 API。
  • 您是否使用了“Microsoft Base Smart Card Crypto Provider”或任何其他 CSP?

标签: c# certificate smartcard cryptoapi


【解决方案1】:

您可以使用 C# 将 PFX/P12 文件导入智能卡,方法是结合使用提供 PFX/P12 文件解析的 X509Certificate2 类和 P/Invoking CryptoAPI 函数来执行实际导入。

我已经在一个复制 certutil 导入功能的 C# 控制台程序中实现了这一点。你可以从http://www.idrix.fr/Root/Samples/PfxImporter.cs获取它的源代码。

如果有人感兴趣,我也在 C++ 中实现了这一点。这是来源:http://www.idrix.fr/Root/Samples/PfxImporter.cpp

最后一点:如智能卡微型驱动程序规范中所述,必须修改两个注册表项以允许使用 MS Base CSP 进行导入操作:

  1. HKLM\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider\ AllowPrivateExchangeKeyImport = DWORD:0x01
  2. HKLM\SOFTWARE\Microsoft\Cryptography\Defaults\Provider\Microsoft Base Smart Card Crypto Provider\ AllowPrivateSignatureKeyImport = DWORD:0x01

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    • 2019-10-19
    • 2011-10-12
    • 2018-05-27
    • 2015-01-04
    相关资源
    最近更新 更多