【问题标题】:javax.net.ssl.SSLException: java.security.ProviderException: Could not derive keyjavax.net.ssl.SSLException:java.security.ProviderException:无法派生密钥
【发布时间】:2018-12-13 13:06:46
【问题描述】:

我正在通过 HttpsURLConnection 发布一个带有参数集的 web 服务。我的 Jdk 版本是 1.8。但是我从 webservice 收到错误。但我找不到问题的解决方案。Stacktrace 如下;

      javax.net.ssl.SSLException: java.security.ProviderException: Could not derive key
at sun.security.ssl.Alerts.getSSLException(Alerts.java:208)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1903)
at sun.security.ssl.SSLSocketImpl.handleException(SSLSocketImpl.java:1886)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1402)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1334)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1309)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:259)
at sikke.cli.helpers.Helpers.sendPost(Helpers.java:75)
at sikke.cli.helpers.Methods.createAccountAndSave(Methods.java:538)
at sikke.cli.helpers.Methods.createAccountAndSave(Methods.java:503)
at sikke.cli.JSONRPC.Methods(JSONRPC.java:28)
at sikke.cli.EchoPostHandler.handle(EchoPostHandler.java:74)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.AuthFilter.doFilter(AuthFilter.java:83)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:82)
at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(ServerImpl.java:675)
at com.sun.net.httpserver.Filter$Chain.doFilter(Filter.java:79)
at sun.net.httpserver.ServerImpl$Exchange.run(ServerImpl.java:647)
at sun.net.httpserver.ServerImpl$DefaultExecutor.execute(ServerImpl.java:158)
at sun.net.httpserver.ServerImpl$Dispatcher.handle(ServerImpl.java:431)
at sun.net.httpserver.ServerImpl$Dispatcher.run(ServerImpl.java:396)
at java.lang.Thread.run(Thread.java:748)

我的帖子连接方法如下;

public String sendPost(String path, String urlParameters) throws Exception {
    String server = system.getConf("server");
    String url = server.equals("1") ? "https:....." : "https:....";
    url += path;

    URL obj = new URL(url);
    HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

    // add reuqest header
    con.setRequestMethod("POST");
    // con.setRequestProperty("User-Agent", USER_AGENT);
    con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    // Send post request
    con.setDoOutput(true);
    try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
        wr.writeBytes(urlParameters);
        wr.flush();
    }

    int responseCode = con.getResponseCode();
    BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuilder response = new StringBuilder();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();
    return response.toString();
}

我哪里做错了。我该如何解决这个问题。

【问题讨论】:

  • 你需要添加 SSLFactory 进行握手试试这个javacodegeeks.com/2014/11/…
  • 您好兄弟,谢谢您的回复。我尝试了您的解决方案,但错误仍然存​​在,没有任何更改。
  • 你成功了吗?
  • 是的,我试过了。问题是;我检测到 API 证书有问题。它给出了一个读写错误。

标签: java web-services webservice-client httpsurlconnection


【解决方案1】:

我遇到了同样的问题,我在更改 sdk 时修复了它。 我从 open jdk 下载了 java8,问题得到了解决。 从此链接下载 --> https://openjdk.java.net/install/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 1970-01-01
    相关资源
    最近更新 更多