我需要从带有包络模式 (p7m) 或包络模式 (p7s) 的签名文件中提取其已签名的原始文件。
我很难弄清楚如何使用 bouncycastle 库来做到这一点。
我同时使用了 BouncyCastle 1.5 和 BouncyCastle 1.4
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(GetOriginalContentFromFileSigned.class);
protected static CMSSignedData extractContent(InputStream buffer) throws IOException, CMSException {
CMSSignedData cms = null;
CMSSignedData signature = new CMSSignedData(buffer);
Store cs = signature.getCertificates();
SignerInformationStore signers = signature.getSignerInfos();
Collection c = signers.getSigners();
Iterator it = c.iterator();
//the following array will contain the content of xml document
byte[] data = null;
while (it.hasNext()) {
SignerInformation signer = (SignerInformation) it.next();
Collection certCollection = cs.getMatches(signer.getSID());
Iterator certIt = certCollection.iterator();
X509CertificateHolder cert = (X509CertificateHolder) certIt.next();
CMSProcessable sc = signature.getSignedContent();
data = (byte[]) sc.getContent();
cms = signature;
}
return cms;
}
protected static byte[] getOriginalDocumentBinaries(InputStream signedDocument) {
try (InputStream is = getOriginalDocumentStream(signedDocument)) {
return IOUtils.toByteArray(is);
} catch (Exception e) {
logger.warn("Unable to retrieve original document binaries", e);
return null;
}
}
分代码摘自https://github.com/esig/dss项目
我缺少什么使方法“getOriginalDocumentBinaries”起作用?对我来说似乎没问题,但我不是充气城堡的专家。
问候。
月关宝盒
慕田峪7331174
相关分类