class CertUtils {

    public static void createPkcs12(String filenameKey, String filenamePem, String filenameP12) throws Exception {
        Security.addProvider(new BouncyCastleProvider());

        KeyPair keyPair = readKeyPairFromPemFile(filenameKey);
        PrivateKey privateKey = keyPair.getPrivate();

        Certificate[] outChain = readCertificateChain(filenamePem);

        KeyStore outStore = KeyStore.getInstance("PKCS12");
        outStore.load(null, InternalSSLKey.getKEY_PASSWORD());
        outStore.setKeyEntry(InternalSSLKey.KEY_ALIAS, privateKey, InternalSSLKey.getKEY_PASSWORD(), outChain);
        try (OutputStream outputStream = new FileOutputStream(filenameP12)) {
            outStore.store(outputStream, InternalSSLKey.getKEY_PASSWORD());
            outputStream.flush();
        }
    }

    private  CertUtils();

}