}else{ FileOutputStream os = new FileOutputStream(keyStoreFilename); ks.store(os, kspassword.toCharArray());
    private void storeKeyStore(KeyStore ks, String username, String kspassword, boolean createJKS,        boolean createPEM)        throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException,             NoSuchProviderException, CertificateException {        log.debug(">storeKeyStore: ks=" + ks.toString() + ", username=" + username);        // Where to store it?        if (mainStoreDir == null) {            throw new IOException("Can't find directory to store keystore in.");        }        String keyStoreFilename = mainStoreDir + "/" + username;        if (createJKS) {            keyStoreFilename += ".jks";        } else {            keyStoreFilename += ".p12";        }        FileOutputStream os = new FileOutputStream(keyStoreFilename);        ks.store(os, kspassword.toCharArray());        // If we should also create PEM-files, do that        if (createPEM) {            String PEMfilename = mainStoreDir + "/pem";            P12toPEM p12topem = new P12toPEM(keyStoreFilename, kspassword, true);            p12topem.setExportPath(PEMfilename);            p12topem.createPEM();        }        log.debug("Keystore stored in " + keyStoreFilename);        log.debug("<storeKeyStore: ks=" + ks.toString() + ", username=" + username);    }