当前位置 : 主页 > 编程语言 > c++ >

初始化证书 - HTTPClient

来源:互联网 收集:自由互联 发布时间:2021-06-30
初始化证书 //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);
        }
    }
网友评论