我正在尝试使用 java Bouncy Castle 1.47 从 CMSSignedData 对象中提取签名者的 X509CertificateObject。到目前为止,我只能提取一个 org.bouncycastle.asn1.x509.Certificate 对象。如何从中获得 X509CertificateObject?非常感谢!
public static X509CertificateObject extractSignersCert(CMSSignedData cmsSignedData)
throws Exception
{
SignerInformationStore signerInfoStore;
SignerInformation signerInfo;
Store certStore;
Collection certCollection;
X509CertificateHolder x509CertHolder;
X509Certificate cert;
X509CertificateObject certObj;
JcaX509CertificateConverter certConverter;
signerInfoStore = cmsSignedData.getSignerInfos();
signerInfo = (SignerInformation) signerInfoStore.getSigners().iterator().next();
certStore = cmsSignedData.getCertificates();
certCollection = certStore.getMatches(signerInfo.getSID());
x509CertHolder = (X509CertificateHolder) certCollection.iterator().next();
certConverter = new JcaX509CertificateConverter();
certConverter.setProvider("BC");
cert = certConverter.getCertificate(x509CertHolder);
certObj = (X509CertificateObject) cert;
return certObj;
}