【问题标题】:Getting "InvalidAlgorithmParameterException" while posting to a HTTPS website发布到 HTTPS 网站时出现“InvalidAlgorithmParameterException”
【发布时间】:2013-05-06 17:26:35
【问题描述】:

我正在尝试使用以下 jsp 代码将数据发布到支付网关网站:

System.setProperty("javax.net.ssl.trustStore ","C:\\Program Files\\Java\\jdk1.7.0_17\\jre\\lib\\security\\cacerts");\
System.setProperty("javax.net.ssl.trustStorePassword","changeit");

URL server = new URL("https://...");

HttpURLConnection connection = (HttpURLConnection) server.openConnection();

connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("content-type","application/x-www-form-urlencoded");

connection.connect();

OutputStream os = connection.getOutputStream();
os.write(checkRequestByte);
os.close();

我已使用以下命令将 .cer 文件添加到 java 密钥库:

keytool -importcert -file "path/certFile.cer" -keystore "Java/jre7/lib/security/cacerts" -alias "Alias"

我也试过这个:

keytool -importcert -file "path/certFile.cer" -keystore "Java/jdk1.7.0_17/jre/lib/security/cacerts" -alias "别名"

在这两种情况下我都收到了这条消息:

证书已添加到密钥库

但是当我运行它并打开页面时,我收到以下错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /process.jsp at line 36

33:     connection.setDoOutput(true);
34:     connection.setRequestProperty("content-type","application/x-www-form-urlencoded");
35: 
36:     connection.connect();
37: 
38:     OutputStream os = connection.getOutputStream();
39:     os.write(checkRequestByte);

javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty ...

我很困惑,我以前从未遇到过...... 我很感激你的cmets

【问题讨论】:

  • 请排除您的 JVM 信任库中没有证书,因为在这种情况下,错误将是 SSLHandshake 错误,也与算法问题无关
  • 对不起,我没听懂,请你解释清楚点好吗?

标签: java jsp keystore sslexception


【解决方案1】:

解决方案非常简单:D,我重新启动了 tomcat,现在它就像一个魅力;)

【讨论】:

    【解决方案2】:

    我在 tomcat 抛出 InvalidAlgorithmParameterException 时遇到了类似的问题。我设置了

     -Djavax.net.ssl.trustStore=/path/to/cacerts
    

    并将站点的证书安装到信任库中,但 https 连接不起作用。最后我在eclipse中为

    设置了一个异常断点
    java.security.InvalidAlgorithmParameterException, 
    

    然后在使用此 sn-p 引发异常时使用 eclipse 中的表达式视图检查系统属性:

    System.getProperty("javax.net.ssl.trustStore")
    

    我看到此 trustStore 位置的值在运行时已更改为与我配置的 -Djavax...trustStore 路径不同的路径。

    我希望这可以帮助某人弄清楚 trustStore 的配置位置,并且可以在运行时将其更改为其他内容。该错误应该真正回显出尝试加载 trustStore 的路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 2022-01-25
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多