public static void addPrivateKey(KeyStore keyStore, File pemKeyFile, char[] passwordChars, List<Certificate> certChain) throws IOException, GeneralSecurityException {
        final String methodName = "addPrivateKey";
        logger.entry(methodName, pemKeyFile, certChain);

        PrivateKey privateKey = createPrivateKey(pemKeyFile, passwordChars);

        keyStore.setKeyEntry("key", privateKey, passwordChars, certChain.toArray(new Certificate[certChain.size()]));

        logger.exit(methodName);
    }
public static void addPrivateKey ( KeyStore keyStore , File pemKeyFile , char [ ] passwordChars , List < Certificate > certChain ) throws IOException , GeneralSecurityException { final String methodName = "addPrivateKey" ; logger . entry ( methodName , pemKeyFile , certChain ) ; PrivateKey privateKey = createPrivateKey ( pemKeyFile , passwordChars ) ; keyStore . setKeyEntry ( "key" , privateKey , passwordChars , certChain . toArray ( new Certificate [ certChain . size ( ) ] ) ) ; logger . exit ( methodName ) ; }
Adds a private key to the specified key store from the passed private key file and certificate chain.

@param keyStore
The key store to receive the private key.
@param pemKeyFile
A PEM format file containing the private key.
@param passwordChars
The password that protects the private key.
@param certChain The certificate chain to associate with the private key.
@throws IOException if the key store file cannot be read
@throws GeneralSecurityException if a cryptography problem is encountered.