1
我试图从pfx文件加载带有私钥的证书并将其导入LocalMachine/My(Personal)证书存储区。我的代码工作,除了罚款,当我查看证书存储区中,它说无法使用私钥导入证书pfx从Windows Server 2012上的.net c#3.5存储
“的相关私钥无法找到”
并进一步的certutil说
“无法找到证书和私钥解密“
奇怪的部分是,我的代码在Windows 7开发盒上工作正常,但在Windows Server 2008 R2或2012上没有问题。另外奇怪的是,如果我使用mmc手动导入pfx文件,私钥似乎仍然存在正常。
这里是代码我使用加载文件并导入:
// load the certificate from pfx file
X509Certificate2 cert = new X509Certificate2(filePath, pfxPassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
// import to the store
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite); //tried MaxAllowed as well
store.Add(caCert);
store.Close();
任何想法?对于背景信息,我也在使用BouncyCastle的早期步骤中生成代码中的证书。我在那一步遇到了一些持续私钥的问题,但是解决了this question的回答。此外,试图导入的代码以管理员身份运行。
参考这个答案,http://stackoverflow.com/questions/749654/associate-private-key-to-certificate-for-pfxexportcertstoreex – Raj
@Raj谢谢你的指针,但我没有明确的使用CryptoAPI在此时此刻。我想知道是否有办法使用c#System.Security.Cryptography.X509Certificates或相关的命名空间来做到这一点... – rusty