static X509Certificate generateCertificate(String issuee, String issuer, int days, String algorithm)
			throws GeneralSecurityException, IOException {
		
		//need to impose a 16 character minimum
		if(issuee.length()<16||issuer.length()<16){
			System.out.println("Issuee/ issuer names not long enough. There is a 16 character minimum.");
			return null;
		}
		else{
		
		//generate a private/public key pair for this cert
		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
    	SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
    	keyGen.initialize(1024, random);
    	
    	KeyPair pair = keyGen.generateKeyPair();
    	
		PrivateKey privkey = pair.getPrivate(); //private key
		PublicKey pubkey = pair.getPublic(); //public key
		X509CertInfo info = new X509CertInfo(); //new info structure for the cert
		Date from = new Date(); //valid from date
		Date to = new Date(from.getTime() + days * 86400000l); //valid to date
		CertificateValidity interval = new CertificateValidity(from, to); //interval of validity
		BigInteger sn = new BigInteger(64, new SecureRandom()); 
		X500Name owner = new X500Name(issuee); //recipient
		X500Name issuedby = new X500Name(issuer); //issuer

		info.set(X509CertInfo.VALIDITY, interval); //setting that info into the cert
		info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn));
		info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner));
		info.set(X509CertInfo.ISSUER, new CertificateIssuerName(issuedby));
		info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic()));
		info.set(X509CertInfo.VERSION, new CertificateVersion(
				CertificateVersion.V3));
		AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid);
		info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo));

		// Sign the cert to identify the algorithm that's used.
		X509CertImpl cert = new X509CertImpl(info);
		cert.sign(privkey, algorithm);

		// Update the algorithm, and resign.
		algo = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG);
		info.set(CertificateAlgorithmId.NAME + "."
				+ CertificateAlgorithmId.ALGORITHM, algo);
		cert = new X509CertImpl(info);
		cert.sign(privkey, algorithm);

		//System.out.println(cert);

		 // Get subject
        Principal principal = cert.getSubjectDN();
        String subjectDn = principal.getName();

        // Get issuer
        principal = cert.getIssuerDN();
        byte[] key = pubkey.getEncoded();
    	FileOutputStream keyfos = new FileOutputStream("./ClientPublicKeys/" + subjectDn + "_pub.key");
    	keyfos.write(key);
    	keyfos.close();
    	
    	PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(
				privkey.getEncoded());
    	FileOutputStream prikeyfos = new FileOutputStream("./ClientPrivateKeys/" + subjectDn + "_pri.key");
    	prikeyfos.write(pkcs8EncodedKeySpec.getEncoded());
    	prikeyfos.close();
		
		/* save the signature in a file */
		File certDest = new File("./ClientCerts/" + subjectDn + ".cer");
		FileOutputStream certout = new FileOutputStream(certDest);
		certout.write(cert.getEncoded());
		certout.close();
		return cert;
		}
	}