我收到了一个来自客户端的p7b文件,该文件应该包含证书链,并且正在尝试使用bouncycastle从中提取证书。
我正在运行最新的1.55
版本的充气城堡,我正在使用你到处看到的代码:
byte [] content = ...;
CMSSignedData data = new CMSSignedData(content);
Store certStore = data.getCertificates();
SignerInformationStore signerInfos = data.getSignerInfos();
Collection<SignerInformation> signers = signerInfos.getSigners();
List<X509Certificate> result = new ArrayList<X509Certificate>();
for (SignerInformation signer : signers) {
Collection<X509CertificateHolder> matches = certStore.getMatches(signer.getSID());
for (X509CertificateHolder holder : matches) {
result.add(new JcaX509CertificateConverter().setProvider("BC").getCertificate(holder));
}
}
return result;
问题是signers
集合为空。
请注意,我能够使用openssl成功提取它们:
openssl pkcs7 -print_certs -in test.p7b -out test.pem
但我宁愿拥有一个干净的基于java的解决方案。我错过了什么吗? CMSSignedData
未正确构建吗?