Java SunTlsRsaPremasterSecret KeyGenerator 不可用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2872520/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 13:54:26  来源:igfitidea点击:

SunTlsRsaPremasterSecret KeyGenerator not available

javamacos

提问by Jill

I encountered an error when my application tries to load a RSA Algorithm provider class from JAVA. The exception stack is as follow:

当我的应用程序尝试从 JAVA 加载 RSA 算法提供程序类时遇到错误。异常堆栈如下:

javax.jms.JMSException: RSA premaster secret error
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:49)
at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1255)
at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1350)
at org.apache.activemq.ActiveMQConnection.setClientID(ActiveMQConnection.java:388)
at com.trendmicro.tmsm.TMSMAgent.open(TMSMAgent.java:63)

Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
at com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:97)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:634)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:226)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:623)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:59)
at org.apache.activemq.transport.tcp.TcpBufferedOutputStream.flush(TcpBufferedOutputStream.java:115)
at java.io.DataOutputStream.flush(DataOutputStream.java:106)
at org.apache.activemq.transport.tcp.TcpTransport.oneway(TcpTransport.java:167)
at org.apache.activemq.transport.InactivityMonitor.oneway(InactivityMonitor.java:237)
at org.apache.activemq.transport.WireFormatNegotiator.sendWireFormat(WireFormatNegotiator.java:168)
at org.apache.activemq.transport.WireFormatNegotiator.sendWireFormat(WireFormatNegotiator.java:84)
at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:74)
at org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:715)
at org.apache.activemq.transport.failover.FailoverTransport.iterate(FailoverTransport.java:115)
at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:122)
at org.apache.activemq.thread.PooledTaskRunner.run(PooledTaskRunner.java:43)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)

Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
at com.sun.net.ssl.internal.ssl.JsseJce.getKeyGenerator(JsseJce.java:223)
at com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:89)
... 22 more

I've googled the error message and most of posts says it's because JVM cannot find sunjce_provider.jar. However, I can find the file in /Library/Java/Home/lib/ext folder.

我用谷歌搜索了错误信息,大多数帖子都说这是因为 JVM 找不到 sunjce_provider.jar。但是,我可以在 /Library/Java/Home/lib/ext 文件夹中找到该文件。

The platform is Mac OS X 10.6 and Java version is 1.6.0_17.

平台为 Mac OS X 10.6,Java 版本为 1.6.0_17。

My questions are:

我的问题是:

  1. Why JVM does not search /Library/Java/Home/lib/ext for jar files?
  2. Can we change CLASSPATH or java.ext.dirs property by modify any config file?
  3. Any suggestion to solve this problem?
  1. 为什么 JVM 不会在 /Library/Java/Home/lib/ext 中搜索 jar 文件?
  2. 我们可以通过修改任何配置文件来更改 CLASSPATH 或 java.ext.dirs 属性吗?
  3. 有什么建议可以解决这个问题吗?

Thanks in advance.

提前致谢。

采纳答案by Jill

I think we find the root cause so here is an answer of my own question.

我认为我们找到了根本原因,所以这里是我自己问题的答案。

  1. the Java system property "java.ext.dirs" in Mac OS X 10.5 is: /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext. The sunjce_provider.jar should be in /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext but also be found in /Library/Java/Extensions/ in the problem mac.

  2. the sunjce_provider.jar in /Library/Java/Extensions/ belongs to Java Cryptography Extension(JCE) 1.2.2, which has been installed in the mac. JCE 1.2.2 is an optional package of J2SE 1.3.1 and may not includes enough libraries for J2SE 1.4 and later.

  3. the Java applcation works normally after all JCE 1.2.2 related jar files have been removed from /Library/Java/Extensions/.

  1. Mac OS X 10.5 中的 Java 系统属性“java.ext.dirs”是:/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0 /家/lib/ext。sunjce_provider.jar 应该在 /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/ext 中,但也可以在问题 mac 的 /Library/Java/Extensions/ 中找到。

  2. /Library/Java/Extensions/中的sunjce_provider.jar属于Java Cryptography Extension(JCE) 1.2.2,mac已经安装。JCE 1.2.2 是 J2SE 1.3.1 的可选包,可能没有为 J2SE 1.4 及更高版本包含足够的库。

  3. 在从 /Library/Java/Extensions/ 中删除所有与 JCE 1.2.2 相关的 jar 文件后,Java 应用程序正常工作。

回答by altumano

I've had the same problem after upgrading to new Java version on Mac. My (maven) project ran OK from command line but got the "SunTlsRsaPremasterSecret" error in Eclipse.

在 Mac 上升级到新的 Java 版本后,我遇到了同样的问题。我的(maven)项目从命令行运行正常,但在 Eclipse 中出现“SunTlsRsaPremasterSecret”错误。

The solution was to remove Installed JREs in Eclipse configuration and add them again (using the "Search..." button).

解决方案是在 Eclipse 配置中删除已安装的 JRE 并再次添加它们(使用“搜索...”按钮)。

回答by Riz

had a similar issue. Adding the classpath to the ext directory fixed it for me. This fix worked for me on windows 7 with java 1.6

有一个类似的问题。将类路径添加到 ext 目录为我修复了它。此修复程序在带有 java 1.6 的 Windows 7 上对我有用

java -Djava.ext.dirs=lib -classpath "%java_home%\lib\ext\*" myapp.jar 

回答by borjab

It happened to me while launching the tomcat server from eclipse. I solved it by changing the configuration in Windows -> Preferences -> Java -> Installed JREs -> Edit. I had to update all the JRE system libraries with the corresponding jars from the folders in:

从 eclipse 启动 tomcat 服务器时发生在我身上。我通过在 Windows -> Preferences -> Java -> Installed JREs -> Edit 中更改配置来解决它。我必须使用以下文件夹中的相应 jar 更新所有 JRE 系统库:

  • %JAVA_HOME%/jre/lib/ext
  • %JAVA_HOME%/jre/lib/
  • %JAVA_HOME%/jre/lib/ext
  • %JAVA_HOME%/jre/lib/

It seems that after the last update I have changed the JRE_Home but forgot those libraries.

似乎在上次更新之后我更改了 JRE_Home 但忘记了那些库。

enter image description here

在此处输入图片说明

回答by Ish Asokan

Had to spend almost a day on this while trying to use JavaMail in Eclipse Luna. Tried all approaches suggested in various forums, but no luck.

在尝试在 Eclipse Luna 中使用 JavaMail 时,不得不花将近一天的时间来解决这个问题。尝试了各种论坛中建议的所有方法,但没有运气。

Digged into the complete flow and found the exception arising due to Class is on BootClassPath

深入整个流程,发现Class引起的异常在BootClassPath上

from KeyAgreement.getInstance()->JceSecurity.canUseProvider()->JceSecurity.getVerificationResult()->JarVerifier.verify()

从 KeyAgreement.getInstance()->JceSecurity.canUseProvider()->JceSecurity.getVerificationResult()->JarVerifier.verify()

void verify() throws JarException, IOException { if (jarURL == null) { throw new JarException("Class is on the bootclasspath"); }.......

void verify() throws JarException, IOException { if (jarURL == null) { throw new JarException("Class is on the bootclasspath"); } ......

I removed sunjce_provider jar from \ext\ folder and can send mail now. This might not be right but atleast a quick workaround.

我从 \ext\ 文件夹中删除了 sunjce_provider jar,现在可以发送邮件了。这可能不正确,但至少是一个快速的解决方法。

Refer Eclipse bug.

请参阅Eclipse 错误

回答by numsu

I also had this issue, noticed that the problem was in my Eclipse configuration.

我也有这个问题,注意到问题出在我的 Eclipse 配置中。

Window > Preferences > Java > Installed JREs > jdk8_64bit > Edit...

The path of my sunjce_provider.jarwas pointing to jdk8_64bit\lib\ext\sunjce.provider.jar. It should point to the JRE's equivalent in jdk8_64bit\jre\lib\ext\sunjce.provider.jar.

我的路径sunjce_provider.jar指向jdk8_64bit\lib\ext\sunjce.provider.jar. 它应该指向 JRE 中的等效项jdk8_64bit\jre\lib\ext\sunjce.provider.jar

回答by Ashish

I know, I am joining late here. But for me, this error came suddenly as soon as I changed the Preference -> Java -> Installed JREs -> Execution Environments as JavaSE-1.8 to jdk1.8 path. But it should be jre1.8 path.

我知道,我来晚了。但是对我来说,一旦我将 Preference -> Java -> Installed JREs -> Execution Environments as JavaSE-1.8 更改为 jdk1.8 路径,这个错误就会突然出现。但是应该是jre1.8路径。

I don't know why is it happening now. But It sorted the problem.

我不知道为什么现在发生了。但它解决了问题。

回答by Pranathi Sadhula

Probable solution: Check if jdk path is set till C:\Program Files\Java\jdk1.8.0_171 but not including bin

可能的解决方案:检查 jdk 路径是否设置为 C:\Program Files\Java\jdk1.8.0_171 但不包括 bin