我有通过MakeCert生成的证书.我想使用PeerTrust将此证书用于WCF消息安全性.如何使用c#或.NET以编程方式将证书安装到"受信任的人"本地计算机证书存储中?
我有一个CER文件,但也可以创建一个PFX.
我相信这是正确的:
using (X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine)) { store.Open(OpenFlags.ReadWrite); store.Add(cert); //where cert is an X509Certificate object }
以下对我有用:
private static void InstallCertificate(string cerFileName) { X509Certificate2 certificate = new X509Certificate2(cerFileName); X509Store store = new X509Store(StoreName.TrustedPublisher, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadWrite); store.Add(certificate); store.Close(); }
而不是将证书安装到需要提升权限的LocalMachine,您可以将其添加到"CurrentUser"(适合我).
X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(cert); //where cert is an X509Certificate object store.Close();