簡體   English   中英

枚舉證書問題(X509Certificate2)

[英]Enumerating Certificates Issue (X509Certificate2)

我試圖在我的服務器上枚舉證書存儲並獲取有關每個證書的信息。 代碼正常工作,但缺少“中間證書頒發機構”商店中找到的所有證書。

string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority",     "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
           for (int x = 0; x < stores.Length; x++)
            {
                X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

                store.Open(OpenFlags.ReadOnly);

                foreach (X509Certificate2 mCert in store.Certificates)
                {
                          //handle certificates
                    }

            }

我最終得到它的工作,由於某種原因,除了“CertificateAuthority”之外的每個商店,你都可以像我在原始代碼中那樣傳遞名稱(stores [x])。 對於“CertificateAuthority”,我必須明確傳遞“Store.CertificateAuthority”。 我覺得這是X509Store類中的一個錯誤。

//Old Code
string[] stores = new string[] { "AddressBook", "AuthRoot", "CertificateAuthority" "Disallowed", "My", "Root", "TrustedPeople", "TrustedPublisher" };
X509Store store = new X509Store(stores[x],StoreLocation.LocalMachine);

//New Code
 X509Store store2= new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine);

對於中間CA存儲,使用“CA”而不是“CertificateAuthority”。 在MSDN中,它只列出商店名稱的枚舉,但它們並不是真正正確的字符串供您傳遞。找到正確商店名稱字符串的一種方法是首先打開StoreName枚舉的商店,然后檢查store.Name值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM