I have a NIO-based application that has to work on a Java 1.4 platform (not Sun/Oracle implementation) and for which I would like to secure the network connections with SSL. But the javax.net.ssl.SSLEngine API is only available starting with Java 5.
Does an alternative, free, pure-Java, implementation of the javax.net.ssl.SSLEngine API exists?
BouncyCastle seems to provide an implementation of JCE, but I did not found javax.net.ssl.SSLEngine in their packages. Did I miss something?
The
SSLEngineengine class is only needed when you want to access to the low-level SSL features, without the socket wrapping. But if you want to secure a network connection using theSSLSocketFactory,SSLServerSocketFactoryor evenHttpsURLConnectionclasses may do the job.An short example code snippet:
Note that if you are not using the Sun JDK/JRE implementation, the "TLS" algorithm implementation may be absent and the
SSLContext.getInstancemay throw aNoSuchAlgorithmException. In that case you should use the BouncyCastle Security Provider.You can add the BC provider with calling:
And request an BC-specific
SSLContextimplementation: