如何在java中使用.crt文件和.key文件连接https
我在网上搜索了一天,但我没有任何线索来解决我的问题 请帮帮我 我在一家银行注册了一个web服务,银行给我发送了2个文件.crt文件和.key文件 在我的客户完成交易后,银行将向我发送一条post请求消息以通知我的服务器(我的服务器收到此消息),但银行要求我通过他们的web服务url(他们的url使用https)发回该消息以进行确认 当我使用java代码发回消息时,我收到了这个异常如何在java中使用.crt文件和.key文件连接https,java,ssl,https,Java,Ssl,Https,我在网上搜索了一天,但我没有任何线索来解决我的问题 请帮帮我 我在一家银行注册了一个web服务,银行给我发送了2个文件.crt文件和.key文件 在我的客户完成交易后,银行将向我发送一条post请求消息以通知我的服务器(我的服务器收到此消息),但银行要求我通过他们的web服务url(他们的url使用https)发回该消息以进行确认 当我使用java代码发回消息时,我收到了这个异常 javax.net.ssl.SSLHandshakeException: Received fatal alert:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
这是我的密码
URL url = new URL("https://bankurlservice");
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
KeyStore ksCACert = KeyStore.getInstance(KeyStore.getDefaultType());
ksCACert.load(new FileInputStream("keystore path"), "keystorepass".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
tmf.init(ksCACert);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
SSLSocketFactory sslSocketFactory = context.getSocketFactory();
urlConnection.setSSLSocketFactory(sslSocketFactory);
BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String res = "";
String inputLine; while ((inputLine = in.readLine()) != null) { res += inputLine; } in.close();
您必须将公钥和证书导入密钥存储:公钥是银行发送给我的.key文件,证书是.crt文件,对吗?