private KeyStore generateToken(String username, String password, int keylength, boolean createJKS)
private KeyStore generateToken(Admin administrator, String username, String password, int keylength, boolean createJKS)
    private KeyStore generateToken(String username, String password, int keylength, boolean createJKS)       throws Exception{         KeyPair rsaKeys = KeyTools.genKeys(keylength);         ISignSessionRemote signsession = signsessionhome.create();         X509Certificate cert = (X509Certificate)signsession.createCertificate(administrator, username, password, rsaKeys.getPublic());        // Make a certificate chain from the certificate and the CA-certificate        CertificateFactory cf = CertificateFactory.getInstance("X.509");        Certificate[] cachain = signsession.getCertificateChain(administrator);        // Verify CA-certificate        if (CertTools.isSelfSigned((X509Certificate)cachain[cachain.length-1])) {            try {                cachain[cachain.length-1].verify(cachain[cachain.length-1].getPublicKey());            } catch (GeneralSecurityException se) {                throw new Exception("RootCA certificate does not verify");            }        }        else            throw new Exception("RootCA certificate not self-signed");        // Verify that the user-certificate is signed by our CA        try {            cert.verify(cachain[0].getPublicKey());        } catch (GeneralSecurityException se) {            throw new Exception("Generated certificate does not verify using CA-certificate.");        }        // Use CommonName as alias in the keystore        //String alias = CertTools.getPartFromDN(cert.getSubjectDN().toString(), "CN");        // Use username as alias in the keystore        String alias = username;        // Store keys and certificates in keystore.        KeyStore ks = null;        if (createJKS)            ks = KeyTools.createJKS(alias, rsaKeys.getPrivate(), password, cert, cachain);        else            ks = KeyTools.createP12(alias, rsaKeys.getPrivate(), cert, cachain);        return ks;    }