这个问题已经在这里有一个答案:
- 为什么SSL握手给“无法生成密钥对DH”异常? 21个回答
我测试的Java应用程序。 我试图使用DH密码组开始SSL握手。 但我收到以下错误:
java.lang.RuntimeException: Could not generate DH keypair
有些人认为BouncyCastle
,但很多人却错误报告用它,所以我不鼓励使用它,如果还有另外一种选择。
一个建议下载Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files
从http://www.oracle.com/technetwork/java/javase/downloads/index.html 。 我也取代了以下两个文件java.security
和java.policy
在C:\Program Files (x86)\Java\jre7\lib\security
。 请注意,我还注意到,我Java\jre7\security
设置中: Program Files (x86)
和Program Files
和我取代两者。 但是,我仍然看到了同样的错误。
是否有此错误的任何解决方法吗?
编辑:堆栈跟踪:
javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.SSLSocketImpl.handleException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at MyClass.MyClass.myFunction(MyProg.java:78)
at MyClass.MyClass.main(MyClass.java:233)
Caused by: java.lang.RuntimeException: Could not generate DH keypair
at sun.security.ssl.DHCrypt.<init>(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverKeyExchange(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
... 4 more
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(Unknown Source)
... 11 more
EDIT2:我的代码是作为客户端试图发起SSL握手与远程服务器(网站)。 我客户的密码套件列表设置为:
{
"TLS_ECDHE_RSA_WITH_RC4_128_SHA",
"TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_RSA_WITH_NULL_SHA",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA"
};
在客户端的列表中的所有密码套件是由Java的支持。 如何配置Java客户端,支持启动时,服务器提供长期DH密钥的SSL握手?