分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > IT知识

openssl生成https证书、转换证书格式的各种相关操作

发布时间:2023-09-06 01:29责任编辑:沈小雨关键词:http

第一步:生成 private key、csr等文件

我们可能需要输入以下信息(交互式):

---Country Name (2 letter code) [AU]:USState or Province Name (full name) [Some-State]:New YorkLocality Name (eg, city) []:BrooklynOrganization Name (eg, company) [Internet Widgits Pty Ltd]:Example Brooklyn CompanyOrganizational Unit Name (eg, section) []:Technology DivisionCommon Name (e.g. server FQDN or YOUR name) []:examplebrooklyn.comEmail Address []:

 上面的信息是一行一行输入的,也可以通过使用 -subj 选项,一步完成

-subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=examplebrooklyn.com"

  

也可以同时生成 private key 和一个 CSR 文件:

openssl req ???????-newkey rsa:2048 -nodes -keyout domain.key ???????-out domain.csr

  -newkey rsa:2048 选项的意思是生成的 key 是通过 RSA 算法生成的 2048 位的。

       -nodes 私钥不需要密码加密

根据现有的私钥生成 CSR 文件:

openssl req ???????-key domain.key ???????-new -out domain.csr

  -key 指定了现有的私钥(private key)

根据现有的 crt 文件和 私钥生成 CSR

openssl x509 ???????-in domain.crt ???????-signkey domain.key ???????-x509toreq -out domain.csr

  -x509toreq 使用 X509 证书生成 CSR

第二步:生成 SSL 证书

生成一个私钥和一个自签名证书:

openssl req ???????-newkey rsa:2048 -nodes -keyout domain.key ???????-x509 -days 365 -out domain.crt

  -days 365  365天有效期

根据现有的私钥生成自签名证书:

openssl req ???????-key domain.key ???????-new ???????-x509 -days 365 -out domain.crt

  

第三步:查看证书

crt 和 csr 文件是使用 PEM 格式编码的,我们无法直接读取文件获取实际的信息。

检查 csr 文件里面的配置信息:

openssl req -text -noout -verify -in domain.csr

  

检查 crt 文件里面的配置信息:

openssl x509 -text -noout -in domain.crt

  

其他:

创建私钥:

openssl genrsa -des3 -out domain.key 2048

  

检验私钥:

openssl rsa -check -in domain.key

  

验证私钥是否匹配 crt 和 csr 文件:

openssl rsa -noout -modulus -in domain.key | openssl md5openssl x509 -noout -modulus -in domain.crt | openssl md5openssl req -noout -modulus -in domain.csr | openssl md5

  

加密私钥:

openssl rsa -des3 ???????-in unencrypted.key ???????-out encrypted.key

  

解密私钥:

openssl rsa ???????-in encrypted.key ???????-out decrypted.key

  

转换证书格式:

转换 PEM到 DER:

openssl x509 ???????-in domain.crt ???????-outform der -out domain.der

  

转换 DER 到 PEM:

openssl x509 ???????-inform der -in domain.der ???????-out domain.crt

  

转换 PEM 到 PKCS7:

可以加入一个或多个 crt 文件。

openssl crl2pkcs7 -nocrl ???????-certfile domain.crt ???????-certfile ca-chain.crt ???????-out domain.p7b

  PKCS7(P7B),被用在 java keystores 和 IIS 中,是一种可以包含 crt 和 ca 证书信息的 ASCII 文件

转换 PKCS7 到 PEM:

openssl pkcs7 ???????-in domain.p7b ???????-print_certs -out domain.crt

  

转换 PEM 到 PKCS12:

openssl pkcs12 ???????-inkey domain.key ???????-in domain.crt ???????-export -out domain.pfx

  

转换 PKCS12 到 PEM 中:

openssl pkcs12 ???????-in domain.pfx ???????-nodes -out domain.combined.crt

  

转换 PEM 到 CER:

openssl x509 -inform PEM -in cacert.pem -outform DER -out certificate.cer

  

openssl生成https证书、转换证书格式的各种相关操作

原文地址:http://www.cnblogs.com/eleven24/p/7993327.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved