SSL请求trustStore的两种注册方式

来源:互联网 发布:3位字母未注册域名 编辑:程序博客网 时间:2024/06/06 12:16

如果是要发起SSL请求,这个时候通常是需要指定trustStore的,当然如果你使用自签名那是不需要的(查看如何使用自签名,查看这篇文章 http://blog.csdn.net/fenglibing/article/details/16842527 )。

一种方式是通过在启动参数中指定,如下:

java -Djavax.net.ssl.trustStore=yourTruststore.jks -Djavax.net.ssl.trustStorePassword=123456 YourApp

还是一种就是通过程序中指定Properties参数进行加载,不过一定要在请求发出之前进行加载,如下:

Properties systemProps = System.getProperties();systemProps.put( "javax.net.ssl.trustStore", "/path/to/yourTruststore.jks");systemProps.put( "javax.net.ssl.trustStorePassword", "trustStorePassword");System.setProperties(systemProps);

如果trustStore没有密码,那以下两种加载方式的参数”javax.net.ssl.trustStorePassword”都是不需要输入的。