X509Certificate2 的私钥无法导出?
在 Win Server 2008 上,我可以执行下面的代码,当我尝试通过 MMC GUI 导出证书时,我也没有导出私钥的选项。但是,如果我使用 GUI 导入证书,我也可以导出私钥。我的代码中缺少什么?
string certfile = @"mycert.p12";
SecureString secString = new SecureString();
foreach (char c in "password")
{
secString.AppendChar(c);
}
X509Certificate2 cert = new X509Certificate2(certfile, secString, X509KeyStorageFlags.Exportable);
var store = new X509Store(StoreName.My , StoreLocation.CurrentUser);
store.Add(cert);
On Win Server 2008, I can execute the code below, and when I try to export the cert via the MMC GUI, I do not have the option to export the private key as well. However, if I use the GUI to import the cert, I am allowed to export the private key also. What am I missing in my code?
string certfile = @"mycert.p12";
SecureString secString = new SecureString();
foreach (char c in "password")
{
secString.AppendChar(c);
}
X509Certificate2 cert = new X509Certificate2(certfile, secString, X509KeyStorageFlags.Exportable);
var store = new X509Store(StoreName.My , StoreLocation.CurrentUser);
store.Add(cert);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊哈。密钥存储标志应该是可导出的并且可以持久保存。
Aha. The key storage flags should be Exportable and persisted.