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();
            }
    
    
        }
    
      
    }
    
  • 相关阅读:
    RIO包 健壮的I/O函数代码
    Upgrading WebLogic Application Environments --官方文档
    JAVA的静态代理与动态代理比较--转载
    指向函数的指针--转
    c之指针与数组(1)
    weblogic 异常常见处理方法
    Redis: under the hood---转载
    A GDB Tutorial with Examples--转
    The best career advice I’ve received --转载
    redis 大数据插入
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691102.html
Copyright © 2011-2022 走看看