/*** * @param filePath 文件的路徑 * @param password 商戶密碼 * @return * @throws Exception */ private SSLContext getSSLContext(String filePath, char[] password) throws Exception { InputStream inputStream = this.getClass().getResourceAsStream(filePath); KeyStore keystore = KeyStore.getInstance("PKCS12"); keystore.load(inputStream, password); SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keystore, password).build(); return sslContext; }
HttpClientBuilder builder = HttpClients.custom(); //如下方法已通過時,待深究 SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory( getSSLContext(), new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); builder.setSSLSocketFactory(sslsf); //完成導入 CloseableHttpClient httpClient = builder.build();
參考java