初始化证书 //String web_inf = request.getServletContext().getRealPath("/WEB-INF/");public SSLContext initSSLContext(String path) { FileInputStream inputStream = null; try { inputStream = new FileInputStream(new File(path + "/tmp.p12"))
//String web_inf = request.getServletContext().getRealPath("/WEB-INF/");
public SSLContext initSSLContext(String path) {
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(new File(path + "/tmp.p12"));
} catch (IOException e) {
throw new RuntimeException("读取证书文件出错", e);
}
try {
KeyStore keystore = KeyStore.getInstance("PKCS12");
char[] partnerId2charArray = MCH_ID.toCharArray();
keystore.load(inputStream, partnerId2charArray);
SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keystore, partnerId2charArray).build();
return sslContext;
} catch (Exception e) {
throw new RuntimeException("证书文件有问题,请核实!", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
}
