OpenSSL 生成pfx证书文件

首先切换到cert目录,以后所有文件都会生成到这个目录中

1、生成.key文件,要求输入一个自定义的密码

openssl genrsa -des3 -out server.key 2048

此时要求输入密码,要求输入两遍

C:\cert>openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
....................................................+++++
..............................................................+++++
e is 65537 (0x010001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:

 

2、生成.crt文件

openssl req -new -x509 -key server.key -out server.crt -days 3650

此时要求输入server.key的密码,同时要输入一些其他内容

C:\cert>openssl req -new -x509 -key server.key -out server.crt -days 3650
Enter pass phrase for server.key:
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]:Tianjin
Locality Name (eg, city) []:Tianjin
Organization Name (eg, company) [Internet Widgits Pty Ltd]:mycorp
Organizational Unit Name (eg, section) []:mycorp
Common Name (e.g. server FQDN or YOUR name) []:mycorp
Email Address []:12345@qq.com

 

3、生成.pfx文件

openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt

此时在cert目录中会生成三个文件,分别为server.key,server.crt,server.pfx

C:\cert>openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
Enter pass phrase for server.key:
Enter Export Password:
Verifying - Enter Export Password:

C:\cert>dir
 驱动器 C 中的卷没有标签。
 卷的序列号是 0621-00F5

 C:\httpstest\cert 的目录

2022/09/01  22:16    <DIR>          .
2022/09/01  22:16    <DIR>          ..
2022/09/01  22:14             1,442 server.crt
2022/09/01  22:11             1,773 server.key
2022/09/01  22:16             2,605 server.pfx
               3 个文件          5,820 字节
               2 个目录 17,112,141,824 可用字节

 

posted on 2022-09-01 22:17  骑着母猪去打猎  阅读(2960)  评论(1编辑  收藏  举报