把证书导入java的cacerts证书库

导入步骤:

cmd进入C:\Program Files\Java\jdk1.5.0_06\jre\lib\security目录
敲入如下命令回车执行
keytool -import -alias cacerts
-keystore C:\Program Files\Java\jdk1.5.0_06\jre\lib\security\cacerts
-file C:\NEXT_CertKey.cer
-trustcacerts
此时命令行会提示你输入cacerts证书库密码,
java中cacerts证书库默认密码为changeit,
Y确认即可,OK,认证已添加至keystore。

测试部分代码:

try {
URL url;
url = new URL("https://next.xxxcorp.cn");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoOutput(true);

BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String input = null;
while ((input = reader.readLine()) != null) {
System.out.println(input);
}
reader.close();
urlConnection.disconnect();
} catch (IOException e) {
e.printStackTrace();
}

你可能感兴趣的:(java)