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 ; } }
This method creates a new PKCS12 format key store containing a named private key and public certificate chain .