https证书生成(openssl)

本文详细介绍如何使用OpenSSL生成服务器端及客户端所需的公钥、私钥,并通过这些密钥生成CA证书,进而为服务器端和客户端生成对应的证书。该过程分为三个步骤:密钥对生成、CA证书生成以及服务器端与客户端证书生成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


第一步,为服务器端和客户端准备公钥、私钥

# 生成服务器端私钥

openssl genrsa -out server.key 1024

# 生成服务器端公钥

openssl rsa -in server.key -pubout -out server.pem

 

# 生成客户端私钥

openssl genrsa -out client.key 1024

# 生成客户端公钥

openssl rsa -in client.key -pubout -out client.pem

第二步,生成 CA 证书

# 生成 CA 私钥

openssl genrsa -out ca.key 1024

# X.509 Certificate Signing Request (CSR) Management.

openssl req -new -key ca.key -out ca.csr

 

# X.509 Certificate Data Management.

openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt

在执行第二步时会出现:

➜ keys openssl req -new -key ca.key -out ca.csr

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]:My CA

Organizational Unit Name (eg, section) []:

Common Name (e.g. server FQDN or YOUR name) []:localhost CN写你的订阅通知回调地址的域名或者IP

Email Address []:

注意,这里的 Organization Name (eg, company) [Internet Widgits Pty Ltd]: 后面生成客户端和服务器端证书的时候也需要填写,不要写成一样的!!!可以随意写如:My CA, My Server, My Client

然后 Common Name (e.g. server FQDN or YOUR name) []: 这一项,是最后可以访问的域名,我这里为了方便测试,写成 localhost,如果是为了给我的网站生成证书,需要写成 barretlee.com

第三步,生成服务器端证书和客户端证书

# 服务器端需要向 CA 机构申请签名证书,在申请签名证书之前依然是创建自己的 CSR 文件

openssl req -new -key server.key -out server.csr

# 向自己的 CA 机构申请证书,签名过程需要 CA 的证书和私钥参与,最终颁发一个带有 CA 签名的证书

openssl x509 -req -days 3650 -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt

 

# client

openssl req -new -key client.key -out client.csr

# client 端到 CA 签名

openssl x509 -req -CA ca.crt -CAkey ca.key -CAcreateserial -in client.csr -out client.crt


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值