【问题标题】:Add an X509 certificate to a store in code将 X509 证书添加到代码中的存储区
【发布时间】:2015-04-17 17:29:20
【问题描述】:

此代码会将 x509 cer 证书文件添加到证书存储区(使用 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);

生成证书的位置:

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

但是 - 这会将证书添加到当前用户的“个人”证书中 - 我如何将证书添加到不同的证书集合中 - 在我的情况下,我想添加到当前用户的“受信任的人”证书中。

谢谢

【问题讨论】:

标签: c# certificate x509certificate


【解决方案1】:
var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);

第一个参数包含要使用哪个商店的枚举,请参阅MSDN

第二个参数包含要使用哪个位置的枚举(例如计算机、当前用户)请参阅MSDN

【讨论】:

    猜你喜欢
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-19
    相关资源
    最近更新 更多