1.说明
keystore和truststore通过jdk的keytool生成即可;.crt和.key生成需要使用openssl。
2.生成keystore
keytool -genkeypair -alias certificatekey -keyalg RSA -validity 365 -keystore tomcat.keystore
输入2次自定义密钥库口令123456,记住该口令
在OpenSSL的bin里面找到tomcat.keystore
3.导出公钥证书cer
keytool -export -alias certificatekey -keystore tomcat.keystore -rfc -file tomcat.cer
执行命令,输入前面自定义的密钥库口令123456
![](https://i-blog.csdnimg.cn/blog_migrate/d750acb127e8aa5082d1c6893c228571.png)
4.生成truststore
Keytool -import -alias certificatekey -file tomcat.cer -keystore tomcat.truststore
5.keystore转换为p12
keytool -importkeystore -srckeystore tomcat.keystore -destkeystore tomcat.p12 -deststoretype PKCS12
6.使用openssl生成.crt
openssl下载路径:
Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions
OpenSSL-Win32-桌面系统文档类资源-CSDN下载(win10以下)
下载OpenSSL-Win32.rar,解压到c盘,进入到bin路径下;将第5步生成的tomcat.p12文件复制到这个路径下。
执行下面命令,生成tomcat.crt。
openssl pkcs12 -in tomcat.p12 -nokeys -out tomcat.crt
7.使用openssl生成.key
openssl pkcs12 -in tomcat.p12 -nocerts -nodes -out tomcat.key