ApacheHTTPClient5中客户端信任商店和SSLContext的密钥库中放置了什么内容?
创始人
2024-09-05 23:00:51
0

Apache HTTP Client 5提供了两个选项来实现HTTPS连接:信任商店和密钥库。TrustStore是包含用于验证服务器证书的受信任证书的存储库。KeyStore是包含客户端证书和私钥的存储库,用于进行客户端身份验证。以下是添加证书到TrustStore和KeyStore的示例:

添加证书到客户端信任商店:

InputStream stream = new FileInputStream("path/to/certificate.crt");

KeyStore truststore = KeyStore.getInstance(KeyStore.getDefaultType());
truststore.load(null, null);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate ca = cf.generateCertificate(stream);
truststore.setCertificateEntry("alias", ca);

SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(truststore, null).build();
CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).build();

添加客户端证书和密钥到KeyStore:

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, null);

InputStream stream = new FileInputStream("path/to/client.p12");
keystore.load(stream, "password".toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keystore, "password".toCharArray());

SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keystore,"password".toCharArray()).build();
CloseableHttpClient client = HttpClients.custom().setSSLContext(sslContext).build();

相关内容

热门资讯

2分钟AI!WepOke辅助挂... 2分钟AI!WepOke辅助挂(透视)wepoke最新下载地址(果然真的有挂)1、这是跨平台的Wep...
9分钟安装!wepoKe辅助挂... 9分钟安装!wepoKe辅助挂(透视)cloudpoker辅助器(其实真的有挂)是一款可以让一直输的...
7分钟口控制!wepOkE辅助... 7分钟口控制!wepOkE辅助挂(透视)gg扑克平台发牌机制(一直真的有挂)您好,gg扑克,确实是有...
一分钟德州!WEPOKE辅助挂... 一分钟德州!WEPOKE辅助挂(透视)微扑克wpk辅助存在(原来真的有挂)1、超多福利:超高返利,海...
1分钟app!wepoke辅助... 1分钟app!wepoke辅助挂(透视)微扑克wpk安全(果真真的有挂);1分钟app!wepoke...
八分钟玄学!WepokE辅助挂... 八分钟玄学!WepokE辅助挂(透视)wpk俱乐部有ai(本来真的有挂)您好,WepokE,确实是有...
7分钟ai辅助!wePokE辅... 7分钟ai辅助!wePokE辅助挂(透视)德州ai智能营销系统(本来真的有挂)1、很好的工具软件,可...
八分钟技巧!wePokE辅助挂... 八分钟技巧!wePokE辅助挂(透视)wopoker用ai有用(的确真的有挂)1、超多福利:超高返利...
两分钟苹果版本!wePOke辅... 两分钟苹果版本!wePOke辅助挂(透视)aa扑克发牌机制(好像真的有挂);人气非常高,ai更新快且...
七分钟猫腻!WEPoke辅助挂... 七分钟猫腻!WEPoke辅助挂(透视)fishpoker大菠萝外挂(一直真的有挂)您好,fishpo...