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();
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(tbsCertificate);
v.add(new AlgorithmIdentifier(sig.getObjectId()));
v.add(struct.getSignature());
// verify
ByteArrayInputStream bIn;
String dump = "";