// 设置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);
}
}
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);
}
}