Tag: let encrypt

在C#中以编程方式将证书和私钥转换为.PFX

我有一个成功的LetsEncrypt证书请求的.cer文件输出。 我有原始私钥用于为LetsEncrypt创建证书签名请求(CSR)。 现在我们需要使用.NET以编程方式将这两个文件组合成一个用于IIS的PFX包 由于我们试图以编程方式执行此操作pvk2pfx不实用,我们希望尽可能避免使用openssl。 为了演示,我们尝试复制此function,但使用CS .NET而不是pvk2pfx:pvk2pfx.exe -pvk Server.pvk -spc Server.cer -pfx Server.pfx 我已经详尽地研究过了,这里有我看到的可能性: 一种方法似乎是使用X509Certificate2,如: // Import the certficate X509Certificate2 cert = new X509Certificate2(“c:\\cert.cer”); // Import the private key X509Certificate2 cert = new X509Certificate2(“c:\\key.pvk”); // Or import the private key – Alternative method X509DecryptString(token, @”c:\CA.pvk”, “mypassword”); // Export the PFX file certificate.Export(X509ContentType.Pfx, “YourPassword”); File.WriteAllBytes(@”C:\YourCert.pfx”, certificateData); 这里有一些其他的方法,但所有这些方法似乎省略了关于私钥的部分或他们需要pvk2pfx.exe […]