throws KeyStoreException, FileNotFoundException, IOException, NoSuchProviderException,
throws KeyStoreException, FileNotFoundException, IOException,
    public void createPEM()        throws KeyStoreException, FileNotFoundException, IOException, NoSuchProviderException,            NoSuchAlgorithmException, CertificateEncodingException, CertificateException,            UnrecoverableKeyException {         if(this.ks == null){            ks = KeyStore.getInstance("JKS");            InputStream in = new FileInputStream(jksFile);            ks.load(in, password.toCharArray());            in.close();        }        // Find the key private key entry in the keystore        Enumeration e = ks.aliases();        Object o = null;        PrivateKey serverPrivKey = null;        while (e.hasMoreElements()) {            o = e.nextElement();            if (o instanceof String) {                if ((ks.isKeyEntry((String) o)) &&                        ((serverPrivKey = (PrivateKey) ks.getKey((String) o, keypass.toCharArray())) != null)) {                    break;                }            }        }        byte[] privKeyEncoded = "".getBytes();        if (serverPrivKey != null) {            privKeyEncoded = serverPrivKey.getEncoded();        }        //Certificate chain[] = ks.getCertificateChain((String) o);        Certificate[] chain = KeyTools.getCertChain(ks, (String) o);         X509Certificate userX509Certificate = (X509Certificate) chain[0];        byte[] output = userX509Certificate.getEncoded();        String sn = CertTools.getSubjectDN(userX509Certificate);        String userFile = CertTools.getPartFromDN(sn, "CN");        String filetype = ".pem";        File path = new File(exportpath);        path.mkdir();        File tmpFile = new File(path, userFile + filetype);        if (!overwrite) {            if (tmpFile.exists()) {                System.out.println("File '" + tmpFile + "' already exists, don't overwrite.");                return;            }        }        OutputStream out = new FileOutputStream(tmpFile);        out.write(beginCertificate);        out.write(NL);        byte[] userCertB64 = Base64.encode(output);        out.write(userCertB64);        out.write(NL);        out.write(endCertificate);        out.close();        tmpFile = new File(path, userFile + "-Key" + filetype);        if (!overwrite) {            if (tmpFile.exists()) {                System.out.println("File '" + tmpFile + "' already exists, don't overwrite.");                return;            }        }        out = new FileOutputStream(tmpFile);        out.write(beginPrivateKey);        out.write(NL);        byte[] privKey = Base64.encode(privKeyEncoded);        out.write(privKey);        out.write(NL);        out.write(endPrivateKey);        out.close();        tmpFile = new File(path, userFile + "-CA" + filetype);        if (!overwrite) {            if (tmpFile.exists()) {                System.out.println("File '" + tmpFile + "' already exists, don't overwrite.");                return;            }        }        if (CertTools.isSelfSigned(userX509Certificate)) {            System.out.println(                "User certificate is selfsigned, this is a RootCA, no CA certificates written.");        } else {            out = new FileOutputStream(tmpFile);            for (int num = 1; num < chain.length; num++) {                X509Certificate tmpX509Cert = (X509Certificate) chain[num];                byte[] tmpOutput = tmpX509Cert.getEncoded();                out.write(beginCertificate);                out.write(NL);                byte[] tmpCACertB64 = Base64.encode(tmpOutput);                out.write(tmpCACertB64);                out.write(NL);                out.write(endCertificate);                out.write(NL);            }            out.close();        }    } // createPEM