惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Jina AI
Jina AI
GbyAI
GbyAI
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
Hugging Face - Blog
Hugging Face - Blog
V
Visual Studio Blog
P
Proofpoint News Feed
The Cloudflare Blog
H
Help Net Security
MyScale Blog
MyScale Blog
T
The Blog of Author Tim Ferriss
量子位
博客园 - 聂微东
Apple Machine Learning Research
Apple Machine Learning Research
T
Tailwind CSS Blog
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
月光博客
月光博客

博客园 - 木头's

.Net读取数字证书信息和扩展域信息 APACHE2.0 TOMCAT5.0 SSL 配置 smimedecryptvbs ASP.NET, Javascript tips: Encrypt /Sign /Verify signed message using Capicom ActiveX .NET and Certificate Stores net平台下的数字签名技术的讲解 java数字签名(签名生成,用证书验证签名) Apache安全应用资源文档 国外PKI/CA体系发展状况 CA基本常识:X.509标准 - 木头's - 博客园 PKI体系的十大风险 在职必看!受益无穷的28条职场语录 启用客户端证书并在 SharePoint Portal Server 2003 的内容搜索中使用客户端证书 一个基于RSA算法的Java数字签名例子 实现在 Linux 下 Tomcat 的双向SSL认证 JAVA对数字证书的常用操作 一组数据摘要算法的效率测试 一首歌曲,一种心情 职场必读
Using CAPICOM to obtain an SSL Certificate
木头's · 2007-08-16 · via 博客园 - 木头's

using System;
using System.Collections;
using System.Security.Cryptography.x509Certificates;
using interop.capicom;

namespace CAPIComWrapper
{
     /// <summary>
     /// Provides methods to interact with Windows Certificate stores.
     /// </summary>
     public class CertificateManager
     {
          /// <summary>
          /// Searches for and returns a particular X509 certificate.
          /// </summary>
          /// <param name="SearchString">A full or partial certificate name</param>
          /// <returns>An instance of the X509Certificate class.</returns>
          public static X509Certificate Get(string SearchString) 
          {
               string storeName = "My"; // "My" indicates the .Default store
               StoreClass oStore;
               Certificates oCerts;
               X509Certificate foundcert = null; System;

               // get a reference to the LOCAL MACHINE certificate store
               oStore = new StoreClass();
               oStore.Open(
                                   CAPICOM_STORE_LOCATION.CAPICOM_LOCAL_MACHINE_STORE,
                                   storeName,
                                   CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY | 
                                   CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY);

               // Get a list of all certificates in the store
               oCerts = (Certificates)oStore.Certificates;

               // get a list of only the matching certificates
               oCerts = (Certificates)oCerts.Find(
                                   CAPICOM_CERTIFICATE_FIND_TYPE.CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME,
                                   SearchString, 
                                   false);

               // do we have any certs?
               if(oCerts.Count > 0)
               {
                    // reference the first certificate
                    Certificate firstcert = (Certificate)oCerts[1] ;

                    // get a certificate context from that cert
                    ICertContext iCertCntxt = (ICertContext) firstcert;

                    // now get a pointer to the context
                    int certcntxt = iCertCntxt.CertContext ;

                    // turn the int pointer into a managed IntPtr
                    IntPtr hCertCntxt = new IntPtr(certcntxt);

                    // was all of this successful?
                    if(hCertCntxt != IntPtr.Zero)
                    { 
                         // create an X509Certificate from the cert context
                         foundcert = new X509Certificate(hCertCntxt);
                    }

                    // free the certificate context
                    iCertCntxt.FreeContext(certcntxt);
               } 
               else
               {
                    foundcert = null;
               }
                return foundcert;
          }
     }
}