class OadrPKISecurity {

	public static OadrUserX509Credential generateCredentials(KeyPair caKeyPair, X509Certificate caCert,
			String commonName, OadrPKIAlgorithm algo) throws OadrSecurityException {
		try {
			long now = System.currentTimeMillis();
			String venCN = commonName;
			BigInteger serialNumber = BigInteger.valueOf(now);

			KeyPair venCred = null;
			String csrAlgo = "";

			if (OadrPKIAlgorithm.SHA256_DSA.equals(algo)) {
				venCred = OadrPKISecurity.generateEccKeyPair();
				csrAlgo = "SHA256withDSA";
			} else if (OadrPKIAlgorithm.SHA256_RSA.equals(algo)) {
				venCred = OadrPKISecurity.generateRsaKeyPair();
				csrAlgo = "SHA256withRSA";
			}

			String x509PrincipalName = "C=FR, ST=Paris, L=Paris, O=Avob, OU=Avob, CN=" + venCN;
			PKCS10CertificationRequest csr = OadrPKISecurity.generateCsr(venCred, x509PrincipalName, csrAlgo);
			X509Certificate crt = OadrPKISecurity.signCsr(csr, caKeyPair, caCert, serialNumber);

			String fingerprint = OadrFingerprintSecurity.getOadr20bFingerprint(crt);

			File crtFile = writeToFile(venCN, "crt", OadrPKISecurity.writeCrtToString(crt));
			File caCrtFile = writeToFile("ca", "crt", OadrPKISecurity.writeCrtToString(caCert));
			File keyFile = writeToFile(venCN, "key", OadrPKISecurity.writeKeyToString(venCred));
			File fingerprintFile = writeToFile(venCN, "fingerprint", fingerprint);

			return new OadrUserX509Credential(fingerprint, caCrtFile, crtFile, keyFile, fingerprintFile);
		} catch (NoSuchAlgorithmException | OperatorCreationException | CertificateException | NoSuchProviderException
				| IOException e) {
			throw new OadrSecurityException(e);
		}

	}

	private  OadrPKISecurity();

}