C#遍历数字证书

来源:互联网 发布:矩阵各元素之和叫什么 编辑:程序博客网 时间:2024/05/18 00:19

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security.Cryptography.X509Certificates;

namespace WebApplication3
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //System.Security.Cryptography.X509Certificates.X509Store
            //System.Security.Cryptography.X509Certificates.X509Store x = new System.Security.Cryptography.X509Certificates.X509Store();
            //string ss = x.Name;

            X509Store store = new X509Store(StoreName.My);
            store.Open(OpenFlags.ReadWrite);
            X509Certificate2 certificate = new X509Certificate2();
            X509Certificate2Collection storecollection3 = (X509Certificate2Collection)store.Certificates;
            string ss = "";
            if (storecollection3.Count == 0)
            {
                Console.WriteLine("Store contains no certificates.");
            }
            else
            {
                foreach (X509Certificate2 x509 in storecollection3)
                {
                    //Console.WriteLine("certificate name: {0}", x509.Subject);
                    ss = ss + "||" + x509.SerialNumber;
                    //x509.Issuer 颁发者
                }
            }
            Response.Write(ss);
        }
    }
}

0 0
原创粉丝点击