一、问题:
常常在用java访问https的请求时,总是出现SSL禁止的异常。这里给大家教下怎么创建与添加证书。
二、工具 :
1、创建一个目录
2、去Github上搜索InstallCert,然后随便下载一下来。比如:https://github.com/escline/InstallCert 把java文件下载到刚创建的这个目录中。
三、代码:
比如我要添加访问azure的几个管理的域名的https。。
就这样:
1、新建一个cert.bat文件。
2、bat中的内容如下:
javac -d ./ ./InstallCert.java
java InstallCert login.chinacloudapi.cn:
keytool -exportcert -alias login.chinacloudapi.cn- -keystore jssecacerts -storepass changeit -file login.chinacloudapi.cn.cer
keytool -importcert -alias login.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jre1.8.0_111\lib\security\cacerts" -storepass changeit -file login.chinacloudapi.cn.cer
keytool -importcert -alias login.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jdk1.8.0_111\jre\lib\security\cacerts" -storepass changeit -file login.chinacloudapi.cn.cer java InstallCert management.core.chinacloudapi.cn:
keytool -exportcert -alias management.core.chinacloudapi.cn- -keystore jssecacerts -storepass changeit -file management.core.chinacloudapi.cn.cer
keytool -importcert -alias management.core.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jre1.8.0_111\lib\security\cacerts" -storepass changeit -file management.core.chinacloudapi.cn.cer
keytool -importcert -alias management.core.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jdk1.8.0_111\jre\lib\security\cacerts" -storepass changeit -file management.core.chinacloudapi.cn.cer java InstallCert management.chinacloudapi.cn:
keytool -exportcert -alias management.chinacloudapi.cn- -keystore jssecacerts -storepass changeit -file management.chinacloudapi.cn.cer
keytool -importcert -alias management.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jre1.8.0_111\lib\security\cacerts" -storepass changeit -file management.chinacloudapi.cn.cer
keytool -importcert -alias management.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jdk1.8.0_111\jre\lib\security\cacerts" -storepass changeit -file management.chinacloudapi.cn.cer java InstallCert graph.chinacloudapi.cn:
keytool -exportcert -alias graph.chinacloudapi.cn- -keystore jssecacerts -storepass changeit -file graph.chinacloudapi.cn.cer
keytool -importcert -alias graph.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jre1.8.0_111\lib\security\cacerts" -storepass changeit -file graph.chinacloudapi.cn.cer
keytool -importcert -alias graph.chinacloudapi.cn -keystore "C:\Program Files (x86)\Java\jdk1.8.0_66\jre\lib\security\cacerts" -storepass changeit -file graph.chinacloudapi.cn.cer java InstallCert xotrmcninfkeyvault01.vault.azure.cn:
keytool -exportcert -alias xotrmcninfkeyvault01.vault.azure.cn- -keystore jssecacerts -storepass changeit -file xotrmcninfkeyvault01.vault.azure.cn.cer
keytool -importcert -alias xotrmcninfkeyvault01.vault.azure.cn -keystore "C:\Program Files (x86)\Java\jre1.8.0_111\lib\security\cacerts" -storepass changeit -file xotrmcninfkeyvault01.vault.azure.cn.cer
keytool -importcert -alias xotrmcninfkeyvault01.vault.azure.cn -keystore "C:\Program Files (x86)\Java\jdk1.8.0_111\jre\lib\security\cacerts" -storepass changeit -file xotrmcninfkeyvault01.vault.azure.cn.cer
好了,管理员权限运行一下这个bat按提示输入yes之类的就可以了。