zoukankan      html  css  js  c++  java
  • 如何查找某个特定证书

    这是昨天课堂上的一个例子。

    image

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;
    using System.Threading;
    using System.Security.Cryptography.X509Certificates;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //查找特定证书
                X509Store store = new X509Store(StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly);
    
    
                string serialNumber = "b101720bccd997a14e64ff649571e20e".ToUpper();
    
                //1.第一种查找:遍历
                X509Certificate2 cert = null;
                foreach (var item in store.Certificates)
                {
                    if (item.SerialNumber == serialNumber)
                    {
                        cert = item; 
                        break;
                    }
                }
                if (cert != null)
                    Console.WriteLine(cert.Subject);
    
    
                //2.第二种查找: 利用Find方法
                X509Certificate2 cert1 = null;
                var found = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber, false);
                if (found != null && found.Count>0)
                {
                    cert1 = found[0];
                    Console.WriteLine(cert1.Subject);
                }
     
                             
                             
    
    
                store.Close();
                
                
    
                
    
                Console.Read();
            }
    
    
        }
    
      
    }
    
  • 相关阅读:
    uva 11404 Palindromic Subsequence(LCS回文串,最小字典序)
    paip.输入法编程---输入法ATIaN历史记录 v8b
    uva 10859 Placing Lampposts (树形dp)
    【设计模式】学习笔记8:命令模式
    Android自定义ProgressDialog
    (二十四)解释器模式详解
    Hadoop--两个简单的MapReduce程序
    BMP图像的灰度化---C++实现
    android 数组数据绑定到listview
    Win64 驱动内核编程-10.突破WIN7的PatchGuard
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691102.html
Copyright © 2011-2022 走看看