首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从DoD CAC卡获取客户端证书

从DoD CAC卡获取客户端证书
EN

Stack Overflow用户
提问于 2011-10-25 00:44:55
回答 2查看 9K关注 0票数 3

我有一个使用LibCurl的C应用程序(LibCurl是一个建立到web服务器的超文本传输协议连接的C应用程序接口)。使用LibCurl时,我需要从需要客户端证书的HTTPS服务器下载文件。

到目前为止,我们的技术解决方案运行良好。

我的问题是,我们需要使用的客户端证书驻留在DoD CAC卡上。我需要能够从DOD CAC卡(从我的C应用程序中)中提取客户端证书,并将其写入文件或仅引用CAC上的文件。然后,这个写入或引用的文件将被指定为我的HTTPS连接中的客户端证书。

我不知道如何查找或引用DoD CAC卡上的客户端证书。任何帮助都是非常感谢的。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-25 00:53:45

当activeClient将CAC卡证书发布到windows时,它应该将证书导出到存储区。您可能需要自动将证书从本地证书存储导出到.pfx或.p7b格式的文件。也许是.cer,我不知道这是否可能。它需要受到pwd的保护。

我认为如果没有中间中间层(如证书存储),您无法直接从CAC卡完成此操作。

票数 3
EN

Stack Overflow用户

发布于 2015-07-24 00:26:59

这是C#的方法,它可能对C很有帮助,我对C代码真的不太熟悉。

代码语言:javascript
复制
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
private static X509Certificate GetClientCert()
{
  X509Store store = null;
  try
   {
    store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);

    var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "Integration Client Certificate", true);
    if (certs.Count == 1)
    {
       var cert = certs[0];
       return cert;
    }
   }
   finally
   {
    if (store != null)
    store.Close();
   }

 return null;
}

获取和导出证书的代码是

代码语言:javascript
复制
//This will bring up the selection prompt to select your cert


X509Certificate c = GetClientCert();


//The password should be the pin converted to a secure string variable.
//note the code above will not prompt for a pin if you want this you will have to build the prompt yourself.  It will only select the certificate.

c.Export(X509ContentType.Cert, securestring password);

导出方法有多种类型可供导出,我不确定其中一种是否为您所引用的格式。这是您需要使用的东西。我甚至不确定你是否能够在C中使用这些库,但为了以防万一,我把它们贴上了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7878952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档