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();
            }
    
    
        }
    
      
    }
    
  • 相关阅读:
    Anaconda+用conda创建python虚拟环境
    Linux安装matlab及简单操作
    Matlab2016b 版本knnclassify函数在Matlab2019b的替换及解决方案
    WIN TO GO实现win10系统迁移
    ArcMap高版本文件保存成低版本
    matlab 保存大于2GB数据
    Tensorflow_gpu + anconda3_3.4.2 +keras2.1.1 + CUDA8.0+CUDNN5.1
    B
    A
    POJ I Think I Need a Houseboat
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691102.html
Copyright © 2011-2022 走看看