public static SSLServerSocketFactory makeSSLSocketFactory(KeyStore loadedKeyStore,KeyManagerFactory loadedKeyFactory) throws IOException {
  SSLServerSocketFactory res=null;
  try {
    TrustManagerFactory trustManagerFactory=TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(loadedKeyStore);
    SSLContext ctx=SSLContext.getInstance("TLS");
    ctx.init(loadedKeyFactory.getKeyManagers(),trustManagerFactory.getTrustManagers(),null);
    res=ctx.getServerSocketFactory();
  }
 catch (  Exception e) {
    throw new IOException(e.getMessage());
  }
  return res;
}

public static SSLServerSocketFactory makeSSLSocketFactory ( KeyStore loadedKeyStore , KeyManagerFactory loadedKeyFactory ) throws IOException { SSLServerSocketFactory res = null ; try { TrustManagerFactory trustManagerFactory = TrustManagerFactory . getInstance ( TrustManagerFactory . getDefaultAlgorithm ( ) ) ; trustManagerFactory . init ( loadedKeyStore ) ; SSLContext ctx = SSLContext . getInstance ( "TLS" ) ; ctx . init ( loadedKeyFactory . getKeyManagers ( ) , trustManagerFactory . getTrustManagers ( ) , null ) ; res = ctx . getServerSocketFactory ( ) ; } catch ( Exception e ) { throw new IOException ( e . getMessage ( ) ) ; } return res ; }
creates an sslsocketfactory for https . pass a loaded keystore and a loaded keymanagerfactory . these objects must properly loaded / initialized by the caller .
