我正在使用itext7进行pdf签名,目前需要支持所有PAdES签名级别:B、B、B、B https://ec.europa.eu/digital-building-blocks/wikis/display/ESIGKB/What+are+the+B-T-LT+and+LTA+levels+of+an+electronic+signature
我的问题是如何用itext创建B签名?我用以下代码创建了B和B:
signer.signDetached(
new BouncyCastleDigest(),
customExternalSignature,
new Certificate[]{clientX509Certificate},
null,
null,
tsaClient,
0,
PdfSigner.CryptoStandard.CADES);
然后我想要添加but级别,所以我使用这个代码https://github.com/mkl-public/testarea-itext7/blob/master/src/main/java/mkl/testarea/itext7/signature/AdobeLtvEnabling.java来检查添加基线-LTA级别,但是在将这个逻辑应用到我的签名adobe之后,说明它是BASELINE。
这就产生了两个问题:
//This method extend B-T signature to B-LT
private byte[] addLt(final byte[] signed) throws IOException, GeneralSecurityException {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try (InputStream resource = new ByteArrayInputStream(signed);
PdfReader pdfReader = new PdfReader(resource);
PdfWriter pdfWriter = new PdfWriter(out);
PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter, new StampingProperties().preserveEncryption().useAppendMode())) {
AdobeLtvEnabling adobeLtvEnabling = new AdobeLtvEnabling(pdfDocument);
IOcspClient ocsp = new OcspClientBouncyCastle(null);
ICrlClient crl = new CrlClientOnline();
adobeLtvEnabling.enable(ocsp, crl);
}
return addLtv(out.toByteArray());
}
//This method extend B-LT signature to B-LTA
private byte[] addLtv(final byte[] pdf) throws IOException, GeneralSecurityException {
final ByteArrayOutputStream signedFile = new ByteArrayOutputStream();
final PdfReader sourceDoc = new PdfReader(new ByteArrayInputStream(pdf));
final PdfSigner signer = new PdfSigner(sourceDoc, signedFile, STAMPING_PROPERTIES);
signer.timestamp(tsaClient, null);
return signedFile.toByteArray();
}
发布于 2022-03-04 20:25:17
看上去差不多。帕迪斯- that和帕德斯-B之间唯一的实质区别是签名验证数据也需要加盖时间戳。因此,要从PAdES到PAdES,只需添加一个文档时间戳就够了。
对于iText,这种工作方式大致如下:
try(InputStream is = ...; // this should contain the PAdES-B-LT output
PdfReader reader = new PdfReader(is);
OutputStream os = new FileOutputStream(OUTPUT_DOCUMENT)) {
PdfSigner pdfSigner = new PdfSigner(reader, os, new StampingProperties().useAppendMode());
// .timestamp(...) is for producing document timestamps
pdfSigner.timestamp(tsaClient, timeStampFieldName);
}
还请参阅这里的一些上下文:https://dzone.com/articles/7-tips-for-creating-pdf-signatures (忽略buzzfeedy的标题.)。
编辑:如果您正在寻找一个工具来测试您的PAdES签名是否符合规范中的格式要求,您可能需要请求访问ETSI一致性检查器:https://signatures-conformance-checker.etsi.org/pub/index.php。
https://stackoverflow.com/questions/71351592
复制相似问题