zoukankan      html  css  js  c++  java
  • 证书之间的转换(crt pem key)

    在ssh协议中,采用一种非对称加密的方式保障通信安全,即a,b通过tcp建立连接后,b生成一对公私钥并将公钥发送给a,a再将密钥用b的公钥发送给a,后续通信便使用密钥加密。
    在https协议中,有证书(ca:包含公钥及其他一些信息)这种存在。即在http的基础上加入ssl层,使数据在传输过程中加密,证书就是这个过程的一个认证官。
    常见公钥后缀:pem crt key
    常见私钥后缀:pfx p12 pem key


    而在api项目中,我们通常是直接利用公私钥要进行数据验证的。
    如果直接得到了一个证书,需要对证书进行转换。

    格式说明
    PKCS 全称是 Public-Key Cryptography Standards ,是由 RSA 实验室与其它安全系统开发商为促进公钥密码的发展而制订的一系列标准,PKCS 目前共发布过 15 个标准。 常用的有:
    PKCS#7 Cryptographic Message Syntax Standard
    PKCS#10 Certification Request Standard
    PKCS#12 Personal Information Exchange Syntax Standard
    X.509是常见通用的证书格式。所有的证书都符合为Public Key Infrastructure (PKI) 制定的 ITU-T X509 国际标准。
    PKCS#7 常用的后缀是: .P7B .P7C .SPC
    PKCS#12 常用的后缀有: .P12 .PFX
    X.509 DER 编码(ASCII)的后缀是: .DER .CER .CRT
    X.509 PAM 编码(Base64)的后缀是: .PEM .CER .CRT
    .cer/.crt是用于存放证书,它是2进制形式存放的,不含私钥。
    .pem跟crt/cer的区别是它以Ascii来表示。
    pfx/p12用于存放个人证书/私钥,他通常包含保护密码,2进制方式
    p10是证书请求
    p7r是CA对证书请求的回复,只用于导入
    p7b以树状展示证书链(certificate chain),同时也支持单个证书,不含私钥。
    用openssl创建CA证书的RSA密钥(PEM格式):
    openssl genrsa -des3 -out ca.key 1024
    用openssl创建CA证书(PEM格式,假如有效期为一年):
    openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config openssl.cnf
    x509转换为pfx
    openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
    PEM格式的ca.key转换为Microsoft可以识别的pvk格式
    pvk -in ca.key -out ca.pvk -nocrypt -topvk
    PKCS#12 到 PEM 的转换
    openssl pkcs12 -nocerts -nodes -in cert.p12 -out private.pem 验证 openssl pkcs12 -clcerts -nokeys -in cert.p12 -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
    用 -outform -inform 指定 DER 还是 PAM 格式。例如:
    openssl x509 -in Cert.pem -inform PEM -out cert.der -outform DER
    PEM 到 PKCS#12 的转换
    openssl pkcs12 -export -in Cert.pem -out Cert.p12 -inkey key.pem
    IIS 证书
    cd c:openssl set OPENSSL_CONF=openssl.cnf openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
    server.key和server.crt文件是Apache的证书文件,生成的server.pfx用于导入IIS
    Convert PFX Certificate to PEM Format for SOAP
    $ openssl pkcs12 -in test.pfx -out client.pem Enter Import Password: MAC verified OK Enter PEM pass phrase: Verifying - Enter PEM pass phrase:
    DER文件(.crt .cer .der)转为PEM格式文件
    转换DER文件(一般后缀名是.crt .cer .der的文件)到PEM文件 openssl x509 -inform der -in certificate.cer -out certificate.pem 转换PEM文件到DER文件 openssl x509 -outform der -in certificate.pem -out certificate.der

    cer文件中导出公钥
    cer转pem
    openssl x509 -inform der -in ***pds.cer -out certificate.pem

    p12 文件导出公钥私钥
    生成key文件
    openssl pkcs12 -in demo.p12 -nocerts -nodes -out demo.key
    导出私钥
    openssl rsa -in demo.key -out demo_pri.pem
    导出公钥
    openssl rsa -in demo.key -pubout -out demo_pub.pem
    ————————————————
    版权声明:本文为CSDN博主「何惜戈」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_37049781/article/details/84837342

  • 相关阅读:
    Intellijidea建javaWeb以及Servlet简单实现
    PHP关于文件与文件夹(1) 写入文件 文件权限 三、锁定文件
    mysql 时间戳格式化函数from_unixtime使用说明
    Ansible 2.0公布
    如何获取板子上独有的ID号EXYNOS4412/Imx6ul【转】
    2.7 xargs和exec详解【转】
    __setup 在内核中的作用【转】
    Linux __setup解析【转】
    c语言中 %p的含义【转】
    函数 devm_kzalloc()【转】
  • 原文地址:https://www.cnblogs.com/telwanggs/p/14977382.html
Copyright © 2011-2022 走看看