从pfx证书中提取file.cer和file.key



我使用这段代码从.pfx证书开始创建.key文件,一切都很好。

////////////////////////////////////////////Create file .key
string cParK = " pkcs12 -in certificate.pfx -out certificate.key -nocerts -nodes -nomacver -password pass:" + cPass;
System.Diagnostics.ProcessStartInfo startInfo2 = new System.Diagnostics.ProcessStartInfo("openssl.exe", cParK);
startInfo2.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo2.CreateNoWindow = true;
System.Diagnostics.Process oProcess2 = System.Diagnostics.Process.Start(startInfo2);
oProcess2.StartInfo.CreateNoWindow = true;
oProcess2.WaitForExit();

有没有任何方法可以在不使用openssl但只使用c#的情况下创建相同的文件?

关于第一个问题,我还找到了导出密钥的解决方案,也许它对那些说这不容易的人也很有用,相反,它非常容易。只需关注此帖子。问题的解决方案

现在我找到了一种提取.cer文件的方法:

System.Security.Cryptography.X509Certificates.X509Certificate2 oCert =
new System.Security.Cryptography.X509Certificates.X509Certificate2("certificate.pfx", "123456");
Byte[] aCert = oCert.Export(System.Security.Cryptography.X509Certificates.X509ContentType.Cert);
File.WriteAllBytes("certificato.cer", aCert);

(我删除了原问题的这一部分(

最新更新