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)
            {
                
    
    
                //读取所有的证书
                string[] storeName = Enum.GetNames(typeof(StoreName));
                string[] storeLocation = Enum.GetNames(typeof(StoreLocation));
    
                foreach (var location in storeLocation)
                {
                    foreach (var name in storeName)
                    {
                        X509Store store = new X509Store(
                            (StoreName)Enum.Parse(typeof(StoreName), name),
                            (StoreLocation)Enum.Parse(typeof(StoreLocation), location));
    
                        
    
                        store.Open(OpenFlags.ReadOnly);
                        Console.WriteLine("当前证书区域:{0},子区域是:{1}", location, name);
                        foreach (var cert in store.Certificates)
                        {
                            Console.WriteLine(cert.Subject);
                        }
                        store.Close();
                        Console.WriteLine();
                    }
                }
    
                
    
                
    
                Console.Read();
            }
    
    
        }
    
      
    }
    

    image

  • 相关阅读:
    asp+access win2008php+mysql /dedecms 配置总结
    js获取页面元素位置函数(跨浏览器)
    Extjs 4 小记
    小总结
    新浪微博 page应用 自适应高度设定 终于找到解决方法
    常用的三层架构设计(转载)
    http://www.jeasyui.com/
    http://j-ui.com/
    日期编辑器MooTools DatePicker
    android布局
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691103.html
Copyright © 2011-2022 走看看