@Test
public void generateCredentialsTest()
		throws NoSuchAlgorithmException, IOException, CertificateException, NoSuchProviderException,
		OadrSecurityException, InvalidKeyException, SignatureException, OperatorCreationException {

	KeyPair ca = OadrPKISecurity.generateRsaKeyPair();
	SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(ca.getPublic().getEncoded());
	AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA256withRSA");
	AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
	Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
	BigInteger sn = new BigInteger(64, new SecureRandom());
	X509v3CertificateBuilder certificateGenerator = new X509v3CertificateBuilder(
			// These are the details of the CA
			new X500Name("cn=TestCa"),
			// This should be a serial number that the CA keeps track of
			sn,
			// Certificate validity start
			Date.from(LocalDateTime.now().minusDays(1).toInstant(ZoneOffset.UTC)),
			// Certificate validity end
			Date.from(LocalDateTime.now().plusDays(365).toInstant(ZoneOffset.UTC)),
			// Blanket grant the subject as requested in the CSR
			// A real CA would want to vet this.
			new X500Name("cn=TestSubject"),
			// Public key of the certificate authority
			subPubKeyInfo);
	ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId)
			.build(PrivateKeyFactory.createKey(ca.getPrivate().getEncoded()));
	X509CertificateHolder holder = certificateGenerator.build(sigGen);
	CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC");
	X509Certificate caCert = (X509Certificate) certificateFactory
			.generateCertificate(new ByteArrayInputStream(holder.toASN1Structure().getEncoded()));
	String commonName = "test.oadr.com";
	// TEST RSA
	OadrUserX509Credential generateCredentials = OadrPKISecurity.generateCredentials(ca, caCert, commonName,
			OadrPKIAlgorithm.SHA256_RSA);
	testGeneratedCredential(generateCredentials, "SHA256withRSA");
	// TEST DSA
	generateCredentials = OadrPKISecurity.generateCredentials(ca, caCert, commonName, OadrPKIAlgorithm.SHA256_DSA);
	testGeneratedCredential(generateCredentials, "SHA256withDSA");
}