通过openssl生成pfx证书

命运对每个人都是一样的,不一样的是各自的努力和付出不同,付出的越多,努力的越多,得到的回报也越多,在你累的时候请看一下身边比你成功却还比你更努力的人,这样,你就会更有动力。

导读:本篇文章讲解 通过openssl生成pfx证书,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

通过centos7上自带的openssl工具来生成。首先创建一个pfxcert目录。然后进入此目录。
1.生成.key文件(内含被加密后的私钥),要求输入一个自定义的密码

[root@localhost cert]# openssl genrsa -des3 -out server.key 2048
Generating RSA private key, 2048 bit long modulus
……….+++
……….+++
e is 65537 (0x10001)
Enter pass phrase for server.key: *****(此处需要键入自定义的密码)
Verifying – Enter pass phrase for server.key:*****(此处需要键入上面的密码,其确认作用)

-des3:对私钥进行加密的算法,key文件中的私钥是被对称加密过的。再解密时,获取对称加密密钥和口令,盐值,迭代次数 有关,根据这些推算出来,但这里的口令不是指的加密密钥。

2.生成.crt文件(公钥证书,这里没有先显示的生成csr文件,然后再根据csr文件生成crt文件)

[root@localhost cert]# openssl req -new -x509 -key server.key -out server.crt -days 18250
Enter pass phrase for server.key: *****(此处需要键入key文件的密码)
You are about to be asked to enter information that will be incorporated
into your certificate request.//表明下面键入的信息会存入csr中,进而根据这些信息创建证书
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) [XX]:CN
State or Province Name (full name) []:Beijing
Locality Name (eg, city) [Default City]:Beijing
Organization Name (eg, company) [Default Company Ltd]:Shihua
Organizational Unit Name (eg, section) []:Shihua
Common Name (eg, your name or your server’s hostname) []:Shihua
Email Address []:12345@qq.com

 3、生成.pfx文件(内含私钥和公钥证书)

[root@localhost cert]# openssl pkcs12 -export -out server.pfx -inkey server.key -in server.crt
Enter pass phrase for server.key:  *****(此处需要键入key文件的密码)
Enter Export Password: *****(此处需要键入自定义的导入pfx证书的密码,最好设置防止他人窃取使用我们的私钥)
Verifying – Enter Export Password:*****(对上方密码的确认)
注意:这里的 Export Password密码和key文件的密码不是一回事。
Export Password密码是来保护我们的pfx文件的。
server.key的密码是用来访问其里面的私钥的。
个人感觉使用pfx文件中的私钥时,不用再输入key文件对应的口令了,所以这里在使用pfx文件时,只需要使用Export Password密码就行,不需要再使用server.key的密码了。 

pfx文件在项目中的使用配置:

server.ssl.key-store=classpath:server.pfx
server.ssl.key-store-password=admin123#    //这里的密码就是设置的Export Password。这里的私钥一般我们是导不出来的,只能导出公钥证书。
server.ssl.keyStoreType=PKCS12

如果想使用keystore格式的证书:
看我另一篇 pfx转keystore格式的博文:(20条消息) pfx证书格式文件转keystore格式_scx_link的博客-CSDN博客_pfx 转keystore通过openssl生成pfx证书https://blog.csdn.net/adminstate/article/details/128870241

yml文件中的配置方式,这里采用的keystore的格式 

server:        
    ssl:
        key-store: classpath:jit.keystore  #密钥文件路径,也可以配置绝对路径
        key-store-password: admin001    #密钥生成时输入的密钥库口令
        keyStoreType: JKS                  #密钥类型,与密钥生成命令一致

这样我们就可以通过浏览器 输入 https://localhost:端口访问我们的项目了。 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/142664.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!