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

  • 相关阅读:
    redmineBUG系统
    MySQL错误代码
    一篇文章全面了解监控知识体系
    K2 blackpearl 流程开发(一)
    HTTP 协议详解
    http协议学习系列
    浅谈HTTP中Get与Post的区别
    iOS应用程序生命周期(前后台切换,应用的各种状态)详解
    深入浅出 iOS 之生命周期
    iOS-利用AFNetworking(AFN 1.x)-实现文件上传
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691103.html
Copyright © 2011-2022 走看看