Add an X509 certificate to a store in code

可紊 提交于 2020-01-02 04:16:06

问题


This code will add a x509 cer cert file into the certificate store (using System.Security.Cryptography.X509Certificates):

    var filename = "Cert.cer";
    var cert = new X509Certificate2(filename);
    var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);

    store.Open(OpenFlags.ReadWrite);
    store.Add(cert);

Where the certificate has been generated with:

makecert -r -pe -sky exchange -n "CN=Blah" Cert.cer -sv Cert.pvk

But - this will add the certificate into the "Personal" certificates of the currentuser - how can I add the certificate to a different collection of certificates - in my case I want to add to the "Trusted People" certificates for currentuser.

Thanks


回答1:


var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);

The First Parameter contains the enumeration for which store to use see MSDN

The Second Parameter contains the enumeration for which location to use (eg Computer, Current user) see MSDN



来源:https://stackoverflow.com/questions/6860352/add-an-x509-certificate-to-a-store-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!