zoukankan      html  css  js  c++  java
  • C# 检测证书是否安装、 安装证书

    检测是否存在指定的证书:
            /// <summary>
            /// 检测是否存在指定的证书
            /// </summary>
            /// <returns></returns>
            static bool CheckCert()
            {
                bool result = false;
                X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                try
                {
                    store.Open(OpenFlags.ReadWrite);
                    foreach (var item in store.Certificates)
                    {
                        if (item.SubjectName.Name == "CN=Client.IOGS.PeopleDaily.BQH")
                        {
                            result = true;
                        }
                    }
                }
                finally
                {
                    store.Close();
                }
                return result;
            }

    安装证书:

    需要以管理员权限运行

                    string certPath = Path.Combine(Application.StartupPath, "Client.IOGS.PeopleDaily.BQH.pfx");
                    
                    X509Certificate2 certificate = new X509Certificate2(certPath, "password01!");
                    X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadWrite);
                    store.Remove(certificate);   //可省略
                    store.Add(certificate);
                    store.Close();
    

      

  • 相关阅读:
    timerfd与eventfd
    boost--asio
    boost--线程
    boost--线程同步
    C++11--lambda表达式
    Java数据类型中String、Integer、int相互间的转换
    Jsoup网页抓取
    线程池
    Java
    用cmd来向mysql导入sql文件
  • 原文地址:https://www.cnblogs.com/zqg123/p/4958752.html
Copyright © 2011-2022 走看看