zoukankan      html  css  js  c++  java
  • 使用openssl进行证书格式转换

     

    各类证书由于存储的内容不同(如是否包含公钥/私钥是否加密存储/单一证书或多证书等)、采用编 码不同(DER/BASE64)、标准不同(如PEM/PKCS),所以尽管X.509标准规定了证书内容规范,但证书文件还是五花八门。好在 openssl对这些不同的标准都有着不错的支持,可以用来进行不同格式证书的转换。

    大体来说,证书转换要作的工作有这么几种


    编码转换:DER<-->BASE64
    不同证书标准的转换:PKCS系列<-->PEM/CER
    私钥的增/减/提取/转换
    ...

    PEM--DER/CER(BASE64--DER编码的转换)

           openssl x509 -outform der -in certificate.pem -out certificate.der

    PEM--P7B(PEM--PKCS#7)

           openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

    PEM--PFX(PEM--PKCS#12)

           openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

    PEM--p12(PEM--PKCS#12)

           openssl pkcs12 -export -out Cert.p12 -in Cert.pem -inkey key.pem

    CER/DER--PEM(编码DER--BASE64)

           openssl x509 -inform der -in certificate.cer -out certificate.pem

    P7B--PEM(PKCS#7--PEM)

           openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

    P7B--PFX(PKCS#7--PKCS#12)

           openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
           openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

    PFX/p12--PEM(PKCS#12--PEM)

           openssl pkcs12 -in certificate.pfx -out certificate.cer
           如无需加密pem中私钥,可以添加选项-nodes;
           如无需导出私钥,可以添加选项-nokeys;

    PEM BASE64--X.509文本格式

           openssl x509 -in Key.pem -text -out Cert.pem

    PFX文件中提取私钥(.key)

           openssl pkcs12 -in mycert.pfx -nocerts -nodes -out mycert.key

    PEM--SPC

           openssl crl2pkcs7 -nocrl -certfile venus.pem -outform DER -out venus.spc

    PEM--PVK(openssl 1.x开始支持)

           openssl rsa -in mycert.pem -outform PVK -pvk-strong -out mypvk.pvk

    PEM--PVK(对于openssl 1.x之前的版本,可以下载pvk转换器后通过以下命令完成)

           pvk -in ca.key -out ca.pvk -nocrypt -topvk

    PVK格式更多参考:http://www.drh-consultancy.demon.co.uk/pvk.html

    openssl更多选项及功能,请参考openssl手册

  • 相关阅读:
    C# 从服务器下载文件
    不能使用联机NuGet 程序包
    NPOI之Excel——合并单元格、设置样式、输入公式
    jquery hover事件中 fadeIn和fadeOut 效果不能及时停止
    UVA 10519 !! Really Strange !!
    UVA 10359 Tiling
    UVA 10940 Throwing cards away II
    UVA 10079 Pizze Cutting
    UVA 763 Fibinary Numbers
    UVA 10229 Modular Fibonacci
  • 原文地址:https://www.cnblogs.com/zhengah/p/5010613.html
Copyright © 2011-2022 走看看