Get list of certificates from the certificate store in C#

后端 未结 4 1501
情歌与酒
情歌与酒 2020-11-29 03:57

For a secure application I need to select a certificate in a dialog. How can I access certificate store or a part of it (e.g. storeLocation=\"Local Machine\" an

4条回答
  •  情深已故
    2020-11-29 04:41

    The simplest way to do that is by opening the certificate store you want and then using X509Certificate2UI.

    var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
    store.Open(OpenFlags.ReadOnly);
    var selectedCertificate = X509Certificate2UI.SelectFromCollection(
        store.Certificates, 
        "Title", 
        "MSG", 
        X509SelectionFlag.SingleSelection);
    

    More information in X509Certificate2UI on MSDN.

提交回复
热议问题