Java SSL异常 - “Prime大小必须是64的倍数...”

时间:2012-02-06 15:13:23

标签: java ssl

我正在尝试实现一个非常简单的SSL客户端来向服务器发送HTTPS POST请求,并且我遇到了这个看似无害的异常。 JSSE参考指南尚未使用。非常感谢。

SSLContext ctx = SSLContext.getInstance("SSL");
// Accept-all trust manager
TrustManager[] trustEverything = { new DefaultTrustManager() };       

// Keystore file in local directory
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(new java.io.FileInputStream("keystore"),"123456".toCharArray());

// Key manager  
KeyManager[] managers;
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, "123456".toCharArray());
managers = kmf.getKeyManagers();

ctx.init(managers, trustEverything, new SecureRandom());
SSLSocketFactory sslFact = (SSLSocketFactory) ctx.getSocketFactory();
// Connect to internal SSL-enabled server
SSLSocket socket = (SSLSocket) sslFact.createSocket("10.131.149.36", 8443);

我尝试握手时会抛出异常:

socket.startHandshake();

我试图找到这些参数初始化的地方无济于事。请让我感到愚蠢。

Caused by: java.security.InvalidAlgorithmParameterException: Prime size must be multiple of 64, and can only range from 512 to 1024 (inclusive)
at     com.sun.crypto.provider.DHKeyPairGenerator.initialize(DHKeyPairGenerator.java:120)
at java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:658)
at sun.security.ssl.DHCrypt.<init>(DHCrypt.java:117)

1 个答案:

答案 0 :(得分:3)

与JCE无关。它是DH密钥大小的硬限制,在&lt; = 1024,Java&lt; 1.8.0。 解决方法如果您遇到的Apache HTTPD服务器问题可能是: http://httpd.apache.org/docs/current/ssl/ssl_faq.html#javadh