问题描述
我使用此代码从.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#来创建相同的文件?
解决方法
对于第一个问题,我还找到了导出密钥的解决方案,也许对于那些说这并不容易,反而非常容易的人,它也很有用。只需关注这篇文章。 Solution of the problem
,目前,我已经找到一种提取.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);
(我删除了原始问题的这一部分)