https

// 设置SSL系统参数
System.setProperty("javax.net.ssl.keyStore",
"E:\\work\\\client1.p12");
System.setProperty("javax.net.ssl.keyStorePassword",
"111111");
System.setProperty("javax.net.ssl.keyStoreType",
"PKCS12");

System.setProperty("javax.net.ssl.trustStore","E:\\work\\src\\truststore.jks");
System.setProper("javax.net.ssl.trustStorePassword",
"123456");


URL urlObj = new URL(url);
HttpsURLConnection httpConn = (HttpsURLConnection) urlObj
.openConnection();


// 设置请求方式为POST
httpConn.setRequestMethod("POST");
// 设置为传值
httpConn.setDoOutput(true);
// 设置为Keep-Alive
httpConn.setRequestProperty("Connection", "Keep-Alive");
httpConn.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});


----------------------------------------------------------------
private static Map<String, SSLContext> map = new HashMap<String, SSLContext>();

public static void regist(String alias, String keyPath, String keyPassword,
String keyType, String trustStorePath, String trustStorePassword,
String trustStoreType) {
try {
// keymanager
KeyStore ks = KeyStoreUtil.loadKeyStore(keyType, keyPath,
keyPassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, keyPassword.toCharArray());

// truststore manager
KeyStore trustKs = KeyStoreUtil.loadKeyStore(trustStoreType,
trustStorePath, trustStorePassword.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustKs);

SSLContext context = SSLContext.getInstance("TLS");
context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
map.put(alias, context);
} catch (Exception e) {
SysLog.err("[SecurityKeyManager:regist] error", e);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值