How to retrieve all certificates in your X509Store

后端 未结 4 661
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 10:07

I am using the following code to retrieve all certificates in my PC from an asp.net webapp. The certificates collection is empty, and I can\'t understand why.

I tri

4条回答
  •  迷失自我
    2021-01-01 10:29

    All in one ...

    I have an apache server (xamp) with https. I access through https and c# (vs2010) to a PHP upload page

    1. Install the certificate from i.e in the personal folder certificate, for example.

    2. To view the certicates run "certmgr.msc" , at least in win7

    Listing the personal certificates

    var store = new X509Store(StoreLocation.CurrentUser); 
    
    store.Open(OpenFlags.ReadOnly); 
    
    var certificates = store.Certificates;
    foreach (var certificate in certificates)
    {
        var friendlyName = certificate.FriendlyName;
        var xname = certificate.GetName(); //obsolete
        Console.WriteLine(friendlyName);
    }
    
    store.Close();
    

    Find specific certificate

    string certificateName = "CN=localhost"; //name found in the var xname
    X509Store storex = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                        storex.Open(OpenFlags.ReadOnly);
    X509Certificate2Collection certificatesx =
                storex.Certificates.Find(X509FindType.FindBySubjectName, 
                certificateName,
                true);
    
    X509Certificate certificatex = certificates[0];
    
    storex.Close();
    

提交回复
热议问题