zoukankan      html  css  js  c++  java
  • 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 签名证书

    1. 首先,到 Cloudflare 申请证书.
      证书申请

    2. 然后 下载/复制 pem格式证书到本地.

    3. (可选)下载Cloudflare官方的CA证书.

      根据你申请证书的加密方式,选择对应的CA证书:

    1. 下载Windows平台最新编译的OpenSSL

    2. 执行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"));
                        });
                    });
    
    
            });
    
  • 相关阅读:
    入职外包一个月的感受!(读者投稿)
    作为架构风格的 REST 到底是什么
    PHP基础之查找
    PHP基础之排序
    PHP入门之数组
    PHP入门之函数
    PHP入门之流程控制
    PHP入门之类型与运算符
    DC-1靶机实战和分析
    【基础算法】 状态压缩DP---蒙德里安的梦想
  • 原文地址:https://www.cnblogs.com/honk/p/14990255.html
Copyright © 2011-2022 走看看