OpenSSL证书转PFX
OpenSSL证书转pfx
pem证书转pfx证书分两种,一种带ca证书转换,一种不带ca证书转换
1. pem转pfx(不带ca证书)
以test.pem转test.pfx为例
openssl rsa -in test.pem -out test.key
openssl x509 -in test.pem -out test.crt
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.crt
2. pem转pfx(带ca证书)
以test.pem和ca.crt(ca.pem)转 test_ca.pfx为例
openssl rsa -in test.pem -out test.key
openssl x509 -in test.pem -out test.crt
openssl pkcs12 -export -out test_ca.pfx -inkey test.key -in test.crt -CAfile ca.crt
3. 如果ca证书为pem格式
openssl pkcs12 -export -out test_ca.pfx -inkey test.key -in test.crt -CAfile ca.pem
openssl pkcs12 -export -out client-ca.pfx -inkey client-key.pem -in client-cert.pem -CAfile cacert.pem
openssl pkcs12 -export -out client.pfx -inkey client-key.pem -in client-cert.pem
主要解决实际场景问题
asp.net https使用Cloudflare 签名证书
-
首先,到 Cloudflare 申请证书.
-
然后 下载/复制 pem格式证书到本地.
-
(可选)下载Cloudflare官方的CA证书.
根据你申请证书的加密方式,选择对应的CA证书:
- RSA加密的选择:Cloudflare Origin RSA PEM
- ECC加密的选择:Cloudflare Origin ECC PEM(不要与 Apache cPanel 一起使用)
-
下载Windows平台最新编译的OpenSSL
-
执行OpenSSL命令
openssl pkcs12 -export -out Cloudflare.pfx -inkey key.pem -in certificate.pem -password pass:"123456"
openssl pkcs12 -export -out Cloudflare2.pfx -inkey key.pem -in certificate.pem -CAfile origin_ca_rsa_root.pem -password pass:"123456"
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>()
.UseKestrel(options =>
{
options.AddServerHeader = false;
options.ListenAnyIP(80);
options.ListenAnyIP(443, lopr =>
{
lopr.UseHttps(
new System.Security.Cryptography.X509Certificates.X509Certificate2(
"Cloudflare.pfx", "123456"));
});
});
});