title: How to load private key password in new (not deprecated) SSLSocketFactory?
body: <p>My current TCP client is building sockets using <code>org.apache.http.conn.ssl.SSLSocketFactory</code><BR>
  I am migrating to <code>import javax.net.ssl.SSLSocketFactory;</code>
  However, I am not sure how to load the private key for the client certificate which is stored in the .p12 file that I already have, as the context for the new SSLSocketFactory?</p>
  
  <p>Here is my existing code, using the deprecated SSLSocketFactory:</p>
  
  <pre><code>import org.apache.http.ssl.SSLContexts;
  import org.apache.http.conn.ssl.SSLSocketFactory;
  
  String ksPassphrase = "myKSpass";
  String pkPassphrase = "myPKpass";
  // Get a keystore instance of type PKCS12:
  KeyStore keystore = KeyStore.getInstance("PKCS12");
  // Load keystore file and password:
  keystore.load(new FileInputStream("myFile.p12"), ksPassphrase.toCharArray());
  // Create HTTPS connection socket factory context:
  SSLContext context = SSLContexts.custom()
      .loadKeyMaterial(keystore, pkPassphrase.toCharArray())
      .build();
  
  SSLSocketFactory sslScktFactory = new SSLSocketFactory(context);
  </code></pre>
  
  <p>Here is the best code I could manage from the docs:</p>
  
  <pre><code>import javax.net.ssl.*;
  
  // not sure if this is the pass to KS or private key or, somehow both?
  String passphrase = "myPassphrase" 
  
  SSLContext context = SSLContext.getInstance("TLS");
  KeyManagerFactory keyMngFactory = KeyManagerFactory.getInstance("SunX509");
  KeyStore keyStore = KeyStore.getInstance("JKS");
  
  keyStore.load(new FileInputStream("myFile.jks"), passphrase.toCharArray());
  keyMngFactory.init(keyStore, passphrase);
  context.init(keyMngFactory.getKeyManagers(), null, null);
  
  SSLSocketFactory sslScktFactory = context.getSocketFactory();
  </code></pre>
  
  <ul>
  <li>I think the problem lies that I don't have a <code>.custom()</code> method for the context under the new library.<BR>
  What to use for the new SSLSocketFactory?</li>
  <li>Is it the case that JKS keystores don't have internal passwords for the private keys stored inside (I only used PKCS until now, not familiar with the JKS format) and that's why I can't see where the private key password is being referred to?</li>
  </ul>