### Question:
KeyStore { void storePrivateKeyEntry(final PrivateKeyEntry keyEntry) throws KeyStoreException { javaKeyStore.setKeyEntry( keyEntry.getAlias(), keyEntry.getPrivateKey(), keyEntry.getPassword().toCharArray(), keyEntry.getCertificateChain() ); this.flush(); } @Builder  KeyStore(
            @NonNull final Path keyStoreFilePath,
            @NonNull final KeyStoreType keyStoreType,
            @NonNull final String keyStorePassword);   }### Answer:
@Test void testStore_PrivateKey_and_Cert_in_PKCS12_KeyStore() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { val fileName = RandomStringUtils.randomAlphabetic(10); keyStoreFilePath = Paths.get(fileName); val keyStoreType = KeyStoreType.getDefaultType(); val keyStorePassword = RandomStringUtils.randomAscii(12); val privateKeyPassword = RandomStringUtils.randomAlphanumeric(12); val keyStore = KeyStore.builder() .keyStoreFilePath(keyStoreFilePath) .keyStoreType(keyStoreType) .keyStorePassword(keyStorePassword) .build(); val privateKeyEntry = PrivateKeyEntry.builder() .alias(ENTRY_ALIAS) .privateKey(x509Svid.getPrivateKey()) .certificateChain(x509Svid.getChainArray()) .password(privateKeyPassword) .build(); keyStore.storePrivateKeyEntry(privateKeyEntry); checkPrivateKeyEntry(keyStoreFilePath, keyStorePassword, privateKeyPassword, keyStoreType, ENTRY_ALIAS); }
@Test void testNewKeyStore_from_existing_file() throws UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { val fileName = RandomStringUtils.randomAlphabetic(10); keyStoreFilePath = Paths.get(fileName); val keyStoreType = KeyStoreType.getDefaultType(); val keyStorePassword = RandomStringUtils.randomAscii(12); val privateKeyPassword = RandomStringUtils.randomAlphanumeric(12); val keyStore = KeyStore.builder() .keyStoreFilePath(keyStoreFilePath) .keyStoreType(keyStoreType) .keyStorePassword(keyStorePassword) .build(); val privateKeyEntry = PrivateKeyEntry.builder() .alias(ENTRY_ALIAS) .privateKey(x509Svid.getPrivateKey()) .certificateChain(x509Svid.getChainArray()) .password(privateKeyPassword) .build(); keyStore.storePrivateKeyEntry(privateKeyEntry); KeyStore.builder() .keyStoreFilePath(keyStoreFilePath) .keyStoreType(keyStoreType) .keyStorePassword(keyStorePassword) .build(); }