im using javamail to send mail in an application. every thing works fine. but when i change the Runtime to jre1.8.25, i got exception as
nested exception is:
javax.net.ssl.SSLKeyException: RSA premaster secret error
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2056)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:697)
at javax.mail.Service.connect(Service.java:364)
at MainClass.main(MainClass.java:44)
Caused by: javax.net.ssl.SSLKeyException: RSA premaster secret error
at sun.security.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:86)
at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:880)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:344)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:936)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:871)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1043)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:574)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:369)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:236)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2020)
... 3 more
Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:158)
at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:207)
at sun.security.ssl.JsseJce.getKeyGenerator(JsseJce.java:272)
at sun.security.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:77)
... 15 more
note: im using latest version of javamail api only.
Make sure the correct sunjce_provider.jar
is on the classpath. If it's in $JAVA_HOME/lib/ext/
, then Java should find it automatically.
See also: