如何将证书添加到Windows证书存储区? [英] How to add a certificate to the windows certificate store?
本文介绍了如何将证书添加到Windows证书存储区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将证书添加到Windows证书库?
我尝试了以下代码。但是证书没有被添加到证书商店。
代码:
How to add a certificate to the windows certificate store?
I tried the below code. But the certificate is not getting added to the certificate store.
Code:
string certificateFilePath=@"C:\Documents and Settings\alexander.junior\Desktop\Test.cer";
// Convert the Filename to an X509 Certificate
X509Certificate2 cert = new X509Certificate2(certificateFilePath);
// Get the server certificate store
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.MaxAllowed);
store.Add(cert); // x509 certificate created from a user supplied filename
推荐答案
你好我认为这应该有用
hello I think this should work
X509Store store = new X509Store(StoreName.My, StoreLocation. LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(certificateFilePath)));
store.Close();
这篇关于如何将证书添加到Windows证书存储区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文