• 如何读取计算机上面所有的证书信息


    这是昨天课堂上一个问题,如何读取到计算机上所有证书的信息呢?我们首先来看一下到底有哪些证书

    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

  • 相关阅读:
    linux下使用脚本自动登录远程服务器 Python language ITeye论坛
    Orbix Programmer's Guide Java Edition
    Automating Capistrano Password Prompts with Expect
    pythondaemon 1.5.5
    linux 技巧:使用 screen 管理你的远程会话
    python daemon
    Jsvc
    Running Java applications as daemon on Debian Linux
    How to run a Java Program as a daemon (service) on Linux (openSUSE) using a shell script
    对话 UNIX: 使用 Screen 创建并管理多个 shell
  • 原文地址:https://www.cnblogs.com/chenxizhang/p/1691103.html
Copyright © 2020-2023  润新知