本机如何模拟CA机构,构建SSL证书
- 安装openssl
- 用OpenSSL生成SSL证书
-
打开openssl.exe 安装盘符>>OpenSSL-Win64>>bin>>openssl.exe
-
输入命令并按回车键
genrsa -des3 -out server.key 2048
-
此时让你输入密码 密码输入后不会显示,两次密码必须一致。
-
输入命令,此时要输入上步设置的密码
req -new -key server.key -out server.csr
如出现 req in error 等命令错误。原因:openssl config文件配置没有找到。需要制定config文件。req -new -key server.key -config “C:/OpenSSL-Win64/bin/openssl.cfg” -out server.csr
-
这个时候会让你输入一些组织信息,要记住自己输入的组织信息
Country Name (2 letter code) [AU]:CN ← 国家代号,中国输入CN
State or Province Name (full name) [Some-State]:Beijing ← 省的全名,拼音
Locality Name (eg, city) []:Beijing ← 市的全名,拼音
Organization Name (eg, company) [Internet Widgits Pty Ltd]:xxx ← 公司英文名
Organizational Unit Name (eg, section) []: ← 可以不输入
Common Name (eg, YOUR name) []: ← 此时不输入
Email Address []:xxxxxx ← 电子邮箱,可随意填Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []: ← 可以不输入
An optional company name []: ← 可以不输入
-
此时已经生成了两个文件
删除私钥中的密码 输入命令rsa -in server.key -out server.key
然后输入之前设置的密码 按回车
-
生成自签名证书,输入命令
x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
此时已经得到三个文件
-
得到pfx格式的私钥,输入命令
pkcs12 -export -out server.pfx -inkey server.key -in server.crt
要输入两遍之前设置的密码
到目前为止已经得到了4个文件
- 现在SSL证书已经生成完毕。
IIS中配置https证书
https默认走443端口,所以要开通443端口
在电脑中找到Internet Information Services (IIS)管理器
双击服务器证书
点击导入证书
选择刚刚生成的pfx文件 并输入之前创建时设置的密码
导入成功
找到程序 点击右键选择编辑绑定
点击添加 弹出添加窗口
类型选择https SSL证书选择刚刚导入成功的证书,其他默认,点击确定。
将网站重新启动,则可以通过https访问程序。