OpenSSL生成CA自签名根证书和颁发证书和证书提取_openssl生成ca证书-程序员宅基地

技术标签: java  运维  openssl  服务器  ca  

CA根证书 生成流程

第一步 生成CA证书私钥
1、#生成ca私钥 (.key 和 pem 只是格式不一样)
openssl genrsa -aes128 -passout pass:Test@2022 -out ca_private.key 2048  # 生成aes128位编码的 密码为Test@2022 2048位的 key 文件  (带密码 、加密格式 aes、des 3des等)
openssl genrsa -out ca_private.key 2048  #生成 2048位的 key 文件  (不带密码,加密格式 等)
     #也可生成  ca_private.pem 文件,将后缀.key 变更为.pem
openssl genrsa -aes128 -passout pass:Test@2022 -out ca_private.pem 2048  # 生成aes128位编码的 密码为Test@2022 2048位的 key 文件  (带密码 、加密格式 aes、des 3des等)
openssl genrsa -out ca_private.pem 2048  #生成 2048位的 key 文件  (不带密码,加密格式 等)

第二步 生成CA证书请求文件 (格式 同第一步)
2、# 有效期20年:
openssl req -new -key ca_private.key -passin pass:Test@2022 -out ca_req.csr -days 7300
     # 也可以 将后缀.key 变更为.pem (注意目录,文件放在哪个目录下,一会用的到,别找不到路径)
openssl req -new -key ca/ca_private.pem  -out ca/ca_req.csr -days 7300 
# 填写 国家、机构、密码等,按实际情况填写即可

第三步、生成CA根证书
3、CA根证书 (注意目录,文件放在哪个目录下,一会用的到,别找不到路径)
openssl x509 -req -in ca_req.csr -signkey ca_private.key -out ca_root.crt -days 7300 -passin pass:Test@2022
   # 也可以 将后缀.key 变更为.pem 
openssl x509 -req -in ca_req.csr -signkey ca_private.pem -out ca_root.pem -days 7300  #不带密码

自此 根证书文件生成完毕 注:接下来服务器证书要根据 以上证书 来生成

第四步、服务器证书生成 与根节点服务器证书类似,只是生成 服务器证书的第三部要依赖 生成的 ca 根证书
4、生成服务器私钥 
openssl genrsa -aes128 -passout pass:Test@2022 -out server_private.key 2048 # 带秘钥 带加密方式 等同 ca 第一步
# 可以 去掉密码 去掉加密 方式
openssl genrsa -out server_private.key 2048 

第五步、生成服务端的待签名证书
5、有效期10年:
openssl req -new -key server_private.key -passin pass:Test@2022 -out server_req.csr -days 3650
    无密码可以去掉密码部分
openssl req -new -key server_private.pem -out server_req.csr -days 3650

第六步、使用CA根证书对服务端证书签名
6、
openssl x509 -req -in server_req.csr -days 3650  -CAkey ca_private.key -CA ca_root.crt -CAcreateserial  -out server.crt
      pem 版本
openssl x509 -req -in server_req.csr -days 3650  -CAkey ca_private.pem -CA ca_root.pem -CAcreateserial  -out server.crt

注 5、6步可以合成:

    $>openssl x509 -req -in xxx/xxx-req.csr -out xxx/xxx-cert.pem -signkey xxx/xxx-key.pem -CA ca/ca-cert.pem -CAkey ca/root-key.pem -CAcreateserial -days 3650  ##签署服务器证书  

        Signature ok
        subject=/C=CN/ST=Zhejiang/L=Hangzhou/O=xxx
        Getting Private key
        Getting CA Private Key

第七步、证书提取
7、
    $>openssl pkcs12 -export -clcerts -in  xxx/xxx-cert.pem -inkey xxx/xxx-key.pem -out xxx/xxx.pfx  #这个是平台的私钥

        Enter Export Password:123456
        Verifying - Enter Export Password:123456

    $>openssl rsa -in xxx-key.pem -pubout -out xxx-pubkey.pem  #提取公钥,这个是平台的公钥
    writing RSA key

双横线上边 和 下边 流程基本一样,上边为理解后 自己总结,下边为快速  生成步骤

=========================================================================

1. 生成CA证书
$>mkdir ca
    $>openssl genrsa -out ca/root-key.pem 2048      ##创建根证书私钥
    $>openssl req -new -out ca/ca-req.csr -key ca/root-key.pem   #创建证书请求

        You are about to be asked to enter information that will be incorporated
        into your certificate request.
        What you are about to enter is what is called a Distinguished Name or a DN.
        There are quite a few fields but you can leave some blank
        For some fields there will be a default value,
        If you enter '.', the field will be left blank.
        -----
        Country Name (2 letter code) [AU]:CN
        State or Province Name (full name) [Some-State]:ZheJiang
        Locality Name (eg, city) []:Hangzhou
        Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxx
        Organizational Unit Name (eg, section) []:
        Common Name (e.g. server FQDN or YOUR name) []:
        Email Address []:
        Please enter the following 'extra' attributes
        to be sent with your certificate request
        A challenge password []:123456
        An optional company name []:

    $>openssl x509 -req -in ca/ca-req.csr -out ca/ca-cert.pem -signkey ca/root-key.pem -days 3650       #自签署根证书
        Signature ok
        subject=/C=CN/ST=ZheJiang/L=Hangzhou/O=xxx
        Getting Private key

    $>openssl pkcs12 -export -clcerts -in ca/ca-cert.pem -inkey ca/root-key.pem -out ca/root.pfx    #导出这PKCS12格式的证书

        Enter Export Password:123456
        Verifying - Enter Export Password:123456
        

2. 创建服务器证书
$>mkdir xxx
    $>openssl genrsa -out xxx/xxx-key.pem 2048     ##创建私钥
    $>openssl req -new -out xxx/xxx-req.csr -key xxx/xxx-key.pem   ##创建证书请求

        You are about to be asked to enter information that will be incorporated
        into your certificate request.
        What you are about to enter is what is called a Distinguished Name or a DN.
        There are quite a few fields but you can leave some blank
        For some fields there will be a default value,
        If you enter '.', the field will be left blank.
        -----
        Country Name (2 letter code) [AU]:CN
        State or Province Name (full name) [Some-State]:Zhejiang
        Locality Name (eg, city) []:Hangzhou
        Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxx
        Organizational Unit Name (eg, section) []:
        Common Name (e.g. server FQDN or YOUR name) []:
        Email Address []:
        Please enter the following 'extra' attributes
        to be sent with your certificate request
        A challenge password []:123456
        An optional company name []:

    $>openssl x509 -req -in xxx/xxx-req.csr -out xxx/xxx-cert.pem -signkey xxx/xxx-key.pem -CA ca/ca-cert.pem -CAkey ca/root-key.pem -CAcreateserial -days 3650  ##签署服务器证书  

        Signature ok
        subject=/C=CN/ST=Zhejiang/L=Hangzhou/O=xxx
        Getting Private key
        Getting CA Private Key

    $>openssl pkcs12 -export -clcerts -in  xxx/xxx-cert.pem -inkey xxx/xxx-key.pem -out xxx/xxx.pfx  #这个是平台的私钥

        Enter Export Password:123456
        Verifying - Enter Export Password:123456

    $>openssl rsa -in xxx-key.pem -pubout -out xxx-pubkey.pem  #提取公钥,这个是平台的公钥,发给合作方侧
    writing RSA key

==================================================================================================================================================

提取:cer证书公钥:

提取命令:
openssl x509 -in XX.cer -pubkey  -noout > XX.pem

如果提示没有这个命令 -noout ,去掉它即可

下面这部分就是 要提取的公钥

 


参考链接:https://blog.csdn.net/qq_44734154/article/details/126167945


 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Javazzc123/article/details/127669548

智能推荐

《Tracking without bells and whistles》翻译和笔记-程序员宅基地

文章浏览阅读677次。机器翻译,日后再核对.摘要The problem of tracking multiple objects in a video sequence poses several challenging tasks. For tracking-bydetection, these include object re-identification, motion prediction and dealing with occlusions. We present a tracker (without b._tracking without bells and whistles

xtrabackup备份脚本_xtrabackup stream备份脚本-程序员宅基地

文章浏览阅读380次。#!/usr/bin/env bash# 配置信息:# mysql 用户名user=root# mysql 密码password='Bgview@2019'# socketsocket=/mysqldata/sgb/data19104/sgrdb19104.sock# 备份路径backup_dir=/mysqldata/mysqlbackup/sgrdb/backup19104# 数据目录datadir=/mysqldata/sgb/data19104# percona-xtrab._xtrabackup stream备份脚本

QT——信号槽-程序员宅基地

文章浏览阅读80次。结合教程,写出如下关于信号槽的代码,将教程中信号槽两种方式写入同一个界面中。#include "mainwindow.h"#include <QApplication>#include <QPushButton>#include <QDebug>#include <QHBoxLayout>int main(int argc, char..._qt 继承qbject 多线程

JSON学习(一)——了解JSON-程序员宅基地

文章浏览阅读201次。简要了解JSON:JavaSrcipt Object Notation:轻量级的数据交换格式。前后端分离开发中作为数据传递与交互的一种数据格式代码// 对象{ key1: value1, key2: value2, ...}// 数组[ { key1: value1, key2: value2 }, { key3: value3, key4: value4 }]// 定义一个JSON对象var obj ={ 1:"value1", "2":"valu_了解json

30 分钟理解 CORB 是什么-程序员宅基地

文章浏览阅读209次。写在前面前些日子在调试 bug 的时候,偶然发现这么一个警告:Cross-Origin Read Blocking (CORB) blocked cross-origin response https://www.chromium.org/ with MIME type text/html. See https://www.chrom..._corb .net

浏览器兼容问题_适用于ie8的文字滚动-程序员宅基地

文章浏览阅读151次。css兼容问题:默认的内外边距不同问题:各个浏览器默认的内外边距不同解决:*{margin:0;padding:0;}水平居中的问题问题:设置 text-align: centerie6-7文本居中,嵌套的块元素也会居中ff /opera /safari /ie8文本会居中,嵌套块不会居中解决:块元素设置1、margin-left:auto;margin-righ..._适用于ie8的文字滚动

随便推点

Windows下64位驱动调试方法_windivert 64位-程序员宅基地

文章浏览阅读4.8k次,点赞2次,收藏8次。尴尬的境地 囧很多时候,我们写的驱动是64位的,而这种64位驱动是不可以在代码中加入_asm int 3 中断来实现在合适的地方进入中断。因为vs此时会报:error C4235: 使用了非标准扩展: 不支持在此结构上使用“_asm”关键字 。而目标平台又要求一定是64位的,因此这就很尴尬了。好在,使用WinDBG可以解决这个问题。核心原理是WinDbg向gdb一样支持 按函数名下断点。因此..._windivert 64位

程序员必须会-mybatis框架的概述、搭建和测试_程序里必有mybatis吗-程序员宅基地

文章浏览阅读2k次。mybatis框架的概述、搭建和测试框架?框架就是:将很多的基础功能进行封装,程序员更关注于业务的开发.mybatis背景:原来是apache的一个开源项目,2010年转投谷歌,从3.0x版本开始改名为mybatis.(了解即可)MyBatis 是一款优秀的java持久层框架。这也就是你给别人说你用到了mybatis框架,就说明你是用Java写的代码.***解释一下持久层:持久层字面理解就是要将数据保存下来,我们的数据比如新增了一条学生记录,要把他保存,就需要通过持久层.即将java对象转化到_程序里必有mybatis吗

图形界面管理笔记_gnome操作界面和windows操作界面有哪些相同和不同之处-程序员宅基地

文章浏览阅读129次。图形界面管理X-Window图形界面发展史1984年美国麻省理工学院与迪吉多(DEC)电脑公司合作制定了Athena计划,在UNIX系统上发展一个分散式的视窗环境,这便是X-Window的第一个版本。1986年,麻省理工学院开始发行X-Window,随后X-Window很快就成为UNIX系统的标准视窗环境。1988年1月成立了一个非营利性的X联盟,负责制定X-Window的标准,并继续发..._gnome操作界面和windows操作界面有哪些相同和不同之处

【Pytorch】谈谈我在PyTorch踩过的12坑-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏8次。点击上方,选择星标或置顶,每天给你送干货!阅读大概需要11分钟跟随小博主,每天进步一丢丢作者 |hyk_1996来源:程序员宅基地编译:程序员大白公众号1. nn.Module.cud..._got input size {}".format(size)

js实现刷新页面图片随机变化_刷新之后swiper图片随机显示-程序员宅基地

文章浏览阅读5.4k次,点赞2次,收藏11次。刷新页面图片随机变化刷新页面,页面其他地方保持不变,图片变化,思路就是取图片路径,将图片路径用字符串数组保存,随机数取其下标,这样图片就能随机变化了,然后就要将获得的图片路径在页面上随机展示,这里我是这么做的,直接贴代码://这是js代码function randomWord (randomFlag, min, max) { let str1 = "", range ..._刷新之后swiper图片随机显示

力扣刷题顺序(数据结构和算法)-程序员宅基地

文章浏览阅读9.2k次,点赞33次,收藏348次。按照题目类别结构化地刷题的速度不仅更快,而且可以在刷完一类题之后进行总结。对于水平较高的小伙伴们来说,按照推荐的顺序刷,可以在 200 小时内刷完 500 多题。对于萌新们来说,按照推荐顺序刷,能更好地掌握数据结构与算法基础。题目分类及刷题顺序推荐一. 数组题目分类 题目编号数组的遍历 485、495、414、628统计数组中的元素 645、697、448、442、41、274数组的改变、移动 453、665、283二维数组及滚动数组 118、119、661、5..._力扣刷题顺序

推荐文章

热门文章

相关标签