java客户端怎么访问带有pfx格式证书的https网站(服务器)呢,
发布网友
发布时间:2022-04-24 01:53
我来回答
共2个回答
热心网友
时间:2023-10-20 04:18
使用HttpURLConnection 访问https地址。
以下是导入JKS证书的方式,可以参考。
String keystorefile = "file";
String keystorepw = "password";
String keypw = "password";
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load( new FileInputStream(keystorefile), keystorepw.toCharArray());
KeyManagerFactory keymanagerfactory = KeyManagerFactory.getInstance("SunX509");
keymanagerfactory.init(keystore, keypw.toCharArray());
KeyManager akeymanager[] = keymanagerfactory.getKeyManagers();
TrustManagerFactory trustmanagerfactory = TrustManagerFactory.getInstance("SunX509");
trustmanagerfactory.init(keystore);
TrustManager atrustmanager[] = trustmanagerfactory.getTrustManagers();
sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(akeymanager, atrustmanager, null);
sslSocketFactory = sslcontext.getSocketFactory();
String url = "asdfdf";
URL testURL = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection) testURL.openConnection();
if (urlConnection instanceof HttpsURLConnection) {
HttpsURLConnection conn = (HttpsURLConnection) urlConnection;
conn.setSSLSocketFactory(sslSocketFactory);
}
热心网友
时间:2023-10-20 04:18
在客户端安装证书
热心网友
时间:2023-10-20 04:18
使用HttpURLConnection 访问https地址。
以下是导入JKS证书的方式,可以参考。
String keystorefile = "file";
String keystorepw = "password";
String keypw = "password";
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load( new FileInputStream(keystorefile), keystorepw.toCharArray());
KeyManagerFactory keymanagerfactory = KeyManagerFactory.getInstance("SunX509");
keymanagerfactory.init(keystore, keypw.toCharArray());
KeyManager akeymanager[] = keymanagerfactory.getKeyManagers();
TrustManagerFactory trustmanagerfactory = TrustManagerFactory.getInstance("SunX509");
trustmanagerfactory.init(keystore);
TrustManager atrustmanager[] = trustmanagerfactory.getTrustManagers();
sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(akeymanager, atrustmanager, null);
sslSocketFactory = sslcontext.getSocketFactory();
String url = "asdfdf";
URL testURL = new URL(url);
HttpURLConnection urlConnection = (HttpURLConnection) testURL.openConnection();
if (urlConnection instanceof HttpsURLConnection) {
HttpsURLConnection conn = (HttpsURLConnection) urlConnection;
conn.setSSLSocketFactory(sslSocketFactory);
}
热心网友
时间:2023-10-20 04:18
在客户端安装证书