certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
certGen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
certGen.setSubjectDN(new X509Principal("CN=Test"));
certGen.setPublicKey(pubKey);
certGen.setSignatureAlgorithm("MD5WithRSAEncryption");
X509Certificate cert = certGen.generate(privKey, "BC");
X509CertificateStructure struct = X509CertificateStructure.getInstance(ASN1Primitive.fromByteArray(cert.getEncoded()));
ASN1Encodable tbsCertificate = struct.getTBSCertificate();
AlgorithmIdentifier sig = struct.getSignatureAlgorithm();