title: Java keystore with multiple keys and different passwords
body: <p>i have created a java JKS keytore: </p>
  
  <pre><code>keytool -genkey -alias mydomain -keyalg RSA -keystore mytest.jks -keysize 2048
  </code></pre>
  
  <p>after that i created a P12 file, using the server's CRT with openssl:</p>
  
  <pre><code>openssl pkcs12 -export -in server.crt -inkey server.key &gt; server.p12
  </code></pre>
  
  <p>now i imported the P12 file into my previously created JKS keystore:</p>
  
  <pre><code>keytool -importkeystore -srckeystore server.p12 -destkeystore mytest.jks -srcstoretype pkcs12
  </code></pre>
  
  <p>It works, i can use this JKS to initialize an SSL connection to the server:</p>
  
  <pre><code>public static SSLContext initSSLContext(String keystoreLocation, String keystorePwd, String truststorePwd, String serverCrtPwd)
  SSLContext context;
  context = SSLContext.getInstance("TLS");
  KeyStore ks = KeyStore.getInstance("JKS");
  ks.load(new FileInputStream(keystoreLocation), keystorePwd.toCharArray());
  KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
  kmf.init(ks, serverCrtPwd.toCharArray());
  
  KeyStore trustStore = KeyStore.getInstance("jks");
  trustStore.load(new FileInputStream(keystoreLocation), truststorePwd.toCharArray());
  TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
  trustManagerFactory.init(trustStore);
  
  context.init(kmf.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
  </code></pre>
  
  <p>Putting the keystore location, password and the password for the imported CRT file in the parameters it works.</p>
  
  <p>Now i have to convert and import multiple P12 files into the same JKS keystore, running the import part multiple times it works, i have multiple keys imported with different alias names and of course with different password. My problem is that now every imported keys have it own password.
  I would like to initialize the SSL connection only once with every available aliases from the given keystore. Because more server will send data to my application with SSL, they have different password, they are imported to my keystore but i cannot initialize my keystore with multiple passwords it accepts only one. How can i init my keystore with multiple imported P12 with different aliases and with different passwords? The init method accepts only one parameter for the "keys recovery from keystore".</p>
  
  <p>Thanks!</p>