1. 安装openssl
openssl官方没有提供windows下的安装文件,使用第三方软件下载地址
选择适合本机的版本下载,我下载的是 Win64 OpenSSL v3.1.2 Light
然后一直下一步安装即可
2. 配置环境变量
在环境变量path末尾添加 安装路径/bin
打开命令行输入 openssl help
检测是否安装成功 出现以下字符就算成功了
3.生成ssl证书
执行以下命令生成密钥 server.key
,过程中会要求设置密码,按提示输入即可
openssl genrsa -des3 -out server.key 2048
输出:
Enter pass phrase for server.key: ---> 输入密码
Verifying - Enter pass phrase for server.key: ---> 验证密码
接下来执行以下命令去除刚刚设置的密码:
openssl rsa -in server.key -out server.key
使用密钥创建服务器证书的申请文件 server.csr
,过程中会要求输入一些信息,不填也可
openssl req -new -key server.key -out server.csr
输出:
D:\Downloads\ssl>openssl req -new -key server.key -out server.csr
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]:BeiJing ---> 省份
Locality Name (eg, city) []:HaiDian ---> 城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:BL ---> 公司
Organizational Unit Name (eg, section) []: ---> 部门(可不填)
Common Name (e.g. server FQDN or YOUR name) []: ---> 域名(可不填)
Email Address []:xxx@gmail.com ---> 邮箱
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:---> 设置密码(可不填)
An optional company name []:---> 可不填
创建 CA 证书 ca.crt
:
openssl req -new -x509 -key server.key -out ca.crt -days 3650
创建服务器证书 server.crt
:
openssl x509 -req -days 3650 -in server.csr -CA ca.crt -CAkey server.key -CAcreateserial -out server.crt
生成后目前目录文件如下: