cat.debug(">createJKS: alias=" + alias + ", privKey, cert=" + cert.getSubjectDN() + ", cachain.length=" + (cachain == null ? 0 : cachain.length) );
log.debug(">createJKS: alias=" + alias + ", privKey, cert=" + cert.getSubjectDN() + ", cachain.length=" + (cachain == null ? 0 : cachain.length) );
    static public KeyStore createJKS(String alias, PrivateKey privKey, String password, X509Certificate cert, Certificate[] cachain)    throws Exception {        cat.debug(">createJKS: alias=" + alias + ", privKey, cert=" + cert.getSubjectDN() + ", cachain.length=" + (cachain == null ? 0 : cachain.length) );        String caAlias="cacert";        // Certificate chain, only max two levels deep unforturnately, this is a TODO:        if (cert == null)            throw new IllegalArgumentException("Parameter cert cannot be null.");        int len = 1;        if (cachain != null)            len += cachain.length;        Certificate[] chain = new Certificate[len];        chain[0] = cert;        if (cachain != null) {            for (int i=0;i<cachain.length;i++) {                chain[i+1] = cachain[i];            }        }        // store the key and the certificate chain        KeyStore store = KeyStore.getInstance("JKS");        store.load(null, null);        if (cachain != null) {            store.setCertificateEntry(caAlias, cachain[cachain.length-1]);        }        store.setKeyEntry(alias, privKey, password.toCharArray(), chain);        cat.debug(">createJKS: alias=" + alias + ", privKey, cert=" + cert.getSubjectDN() + ", cachain.length=" + (cachain == null ? 0 : cachain.length));        return store;    } // createJKS