private SSLContext getSSLContext ( String truststorePath , String truststorePassword , String keystorePath , String keystorePassword ) throws Exception { FileInputStream tsf = new FileInputStream ( truststorePath ) ; KeyStore ts = KeyStore . getInstance ( "JKS" ) ; ts . load ( tsf , truststorePassword . toCharArray ( ) ) ; TrustManagerFactory tmf = TrustManagerFactory . getInstance ( TrustManagerFactory . getDefaultAlgorithm ( ) ) ; tmf . init ( ts ) ; FileInputStream ksf = new FileInputStream ( keystorePath ) ; KeyStore ks = KeyStore . getInstance ( "JKS" ) ; ks . load ( ksf , keystorePassword . toCharArray ( ) ) ; KeyManagerFactory kmf = KeyManagerFactory . getInstance ( KeyManagerFactory . getDefaultAlgorithm ( ) ) ; kmf . init ( ks , keystorePassword . toCharArray ( ) ) ; SSLContext ctx = SSLContext . getInstance ( "SSL" ) ; ctx . init ( kmf . getKeyManagers ( ) , tmf . getTrustManagers ( ) , new SecureRandom ( ) ) ; return ctx ; }
Build an SSLContext from the given truststore and keystore parameters .