code: public final KeyStore createPkcs12KeyStore(String keyName, char[] password, PrivateKey privateKey, List<X509Certificate> certificates) {
          try {
              logger.entry();
              X509Certificate[] chain = new X509Certificate[certificates.size()];
              chain = certificates.toArray(chain);
              KeyStore keyStore = KeyStore.getInstance(KEY_STORE_FORMAT);
              keyStore.load(null, null);
              keyStore.setKeyEntry(keyName, privateKey, password, chain);
              logger.exit();
              return keyStore;
          } catch (IOException | KeyStoreException | NoSuchAlgorithmException | CertificateException e) {
              RuntimeException exception = new RuntimeException("An unexpected exception occurred while attempting to create a new keystore.", e);
              logger.error(exception.toString());
              throw exception;
          }
      }
docs: This method creates a new PKCS12 format key store containing a named private key and public certificate chain.
  
  @param keyName The name of the private key and public certificate.
  @param password The password used to encrypt the private key.
  @param privateKey The private key.
  @param certificates The chain of X509 format public certificates.
  @return The new PKCS12 format key store.