创建和签名 X509 证书

您可以使用 OpenSSL 为应用程序创建 X509 证书。OpenSSL 一种支持广泛加密功能的标准开源库,其功能包括创建和签名 X509 证书。想要了解更多有关 OpenSSL 的信息,请访问www.openssl.org/

在window上我们可以使用gitbash自带的openssl创建证书

创建 RSA 私有密钥。

使用 openssl genrsa 命令创建私有秘钥:

$ openssl genrsa 2048 > privatekey.pem
Generating RSA private key, 2048 bit long modulus
..................+++
............................................................+++
e is 65537 (0x10001)

privatekey.pem

创建CRS

CSR 是指您为申请数字服务器证书而发送至证书颁发机构 (CA) 的文件。要创建 CSR,请使用 openssl req 命令:

$ openssl req -new -key privatekey.pem -out csr.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]:si chuang
Locality Name (eg, city) []:cheng du
Organization Name (eg, company) [Internet Widgits Pty Ltd]:arialyy
Organizational Unit Name (eg, section) []:aria
Common Name (e.g. server FQDN or YOUR name) []:www.laoyuyu.me
Email Address []:laoyuyu@laoyuyu.me

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:

输入所请求的信息并按 Enter。下表描述并显示每个字段的示例:

名称 描述 示例
国家/地区名称 代表国家/地区的两个字母 ISO 缩写。 CN = 中国
州或省 组织所在州或省的名称。不能缩写此名称。 si chuang
所在地名称 组织所在城市的名称。 cheng du
组织名称 组织的法定全称。请勿缩写组织名称。 arialyy
组织部门 可选,用于提供额外的组织信息。 aria
公用名 网站的完全限定域名。这必须与用户访问站点时看到的域名相符,否则将显示证书错误。 www.laoyuyu.me
电子邮件地址 站点管理员的电子邮件地址。 laoyuyu@laoyuyu.me

自签名

您可向第三方提交签名请求以供签名,或自行签名以供开发和测试。自签名证书也在负载均衡器和 EC2 实例之间用于后端 HTTPS。
要对证书进行签名,请使用 openssl x509 命令。以下示例使用来自上一步骤 (privatekey.pem) 和签名请求 (csr.pem) 的私钥来创建名为 server.crt 的公有证书,该证书的有效期为 365 天。

$ openssl x509 -req -days 365 -in csr.pem -signkey privatekey.pem -out server.crt
Signature ok
subject=/C=CN/ST=si chuang/L=cheng du/O=arialyy/OU=aria/CN=www.laoyuyu.me/emailAddress=laoyuyu@laoyuyu.me
Getting Private key

一切顺利的话会生成下面几个文件

参考地址

AWS创建https证书

作者

AriaLyy

发布于

2018-07-17

许可协议

CC BY-NC-SA 4.0

评论