Package ej.net.util.ssl
Class SslContextFactory
- java.lang.Object
-
- ej.net.util.ssl.SslContextFactory
-
public class SslContextFactory extends Object
Provides utility methods to create SSL contexts.The following snippet shows how to create a SSL context for a client:
X509Certificate certificate = CertificatesHelper.getCertificate(CERTIFICATE_PATH); X509TrustManager trustManager = SslContextFactory.createTrustManager(certificate); SSLContext sslContext = SslContextFactory.createSslContext(SslProtocols.TLS, trustManager);
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static X509KeyManagercreateKeyManager(byte[] key, char[] keyPassword, X509Certificate... certificateChain)Creates a key manager that stores the given key and its associated certificate chain.static SSLContextcreateSslContext(String protocol, TrustManager trustManager, KeyManager... keyManagers)Creates a SSL context.static X509TrustManagercreateTrustManager(X509Certificate... certificates)Creates a trust manager that stores the given certificates.
-
-
-
Method Detail
-
createSslContext
public static SSLContext createSslContext(String protocol, TrustManager trustManager, KeyManager... keyManagers)
Creates a SSL context.The
createTrustManager(java.security.cert.X509Certificate...)andcreateKeyManager(byte[], char[], java.security.cert.X509Certificate...)methods can be used to create the trust manager and the key managers easily.- Parameters:
protocol- the protocol (seeSslProtocols).trustManager- the trust manager.keyManagers- the key managers.- Returns:
- the new SSL context.
-
createTrustManager
public static X509TrustManager createTrustManager(X509Certificate... certificates)
Creates a trust manager that stores the given certificates.- Parameters:
certificates- the trusted certificates.- Returns:
- the new trust manager.
-
createKeyManager
public static X509KeyManager createKeyManager(byte[] key, char[] keyPassword, X509Certificate... certificateChain)
Creates a key manager that stores the given key and its associated certificate chain.- Parameters:
key- the key.keyPassword- the password to decrypt the key.certificateChain- the certificate chain.- Returns:
- the new key manager.
-
-