JcaContentSignerBuilder contentSignerBuilder = new JcaContentSignerBuilder(request.getSignAlgorithm());
contentSignerBuilder.setProvider(BouncyCastleProviderHelper.PROVIDER_NAME);
if ((request.getIssuerPrivateKey() != null) && (request.getIssuerCertificate() != null)) {
builder = new JcaX509v3CertificateBuilder(request.getIssuerCertificate(), request.getSerialNumber(), request.getNotBefore(), request.getNotAfter(), request.getSubjectAsX500Principal(), request.getPublicKey());
AuthorityKeyIdentifier authorityKeyIdentifier = new JcaX509ExtensionUtils().createAuthorityKeyIdentifier(request.getIssuerCertificate());
builder.addExtension(X509Extension.authorityKeyIdentifier, false, authorityKeyIdentifier);
contentSigner = contentSignerBuilder.build(request.getIssuerPrivateKey());
} else {
builder = new JcaX509v3CertificateBuilder(request.getIssuerAsX500Name(), request.getSerialNumber(), request.getNotBefore(), request.getNotAfter(), request.getSubjectAsX500Name(), request.getPublicKey());
contentSigner = contentSignerBuilder.build(request.getPrivateKey());