How to retrieve all certificates in your X509Store

后端 未结 4 695
被撕碎了的回忆
被撕碎了的回忆 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:42

    I can find certificates by ...

    var certificateStore = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
    
    certificateStore.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
    
    var certificateCollection = certificateStore.Certificates.Find(X509FindType.FindBySubjectName, "mycert.me.com",false);
    
    certificateStore.Close();
    
    var certificate = certificateCollection[0];
    

    certificateCollection will have the certificates I care about ... if it is just one then I get first element in the collection.

提交回复
热议问题