我读过许多关于如何使用iText启用pdf ltv的问题/答案。他们两个人都不为我工作。我有一个pdf的蒸汽,我设置了一个签名字段,然后我使用,以调用signDetached方法和签署的pdf。我用:
signer.signDetached(new BouncyCastleDigest(), pks, chain,
Collections.singleton(crlClient), ocspClient, tsc,0, subfilter);但什么都没发生。我读到你必须包括除根外的所有证书。我添加了我的私人证书链(我使用它来签署pdf),但我还没有找到一种可能的方法包括TSA的证书。
我使用iText版本7.X。
KeyStore ks = getKeyStore();
Certificate[] chain = null;
Enumeration<String> al = ks.aliases();
for (Enumeration<String> l = al; l.hasMoreElements();) {
String alias = (String) l.nextElement();
chain = ks.getCertificateChain(alias);
}
PrivateKey pk = (PrivateKey) ks.getKey(ks.aliases().nextElement(), "******".toCharArray());
IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, BouncyCastleProvider.PROVIDER_NAME);
OCSPVerifier ocspVerifier = new OCSPVerifier(null, null);
OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle(ocspVerifier);
String url = CertificateUtil.getCRLURL((X509Certificate) chain[0]);
CrlClientOnline crlClient = new CrlClientOnline(url);
try {
signer.signDetached(new BouncyCastleDigest(), pks, chain, Collections.singleton(crlClient), ocspClient, tsc,
0, subfilter);
} catch (Exception ex) {
System.out.println("Tzizzzzzzzzzzzzzzz" + ex.getCause());
}
private KeyStore getKeyStore()
throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException {
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream("tsaPath"), "****".toCharArray());
ks.load(new FileInputStream("p12Path"), "*******".toCharArray());
return ks;
}发布于 2021-10-28 04:41:23
如果有人还对adobeLTV有问题的话。与itext5中的情况一样,仍然需要用itext7来启用AdobeLTV,您需要自己创建文档安全存储,并在间接引用信息中添加有关验证数据/ocsp/crls/certs的信息。
发布于 2019-02-14 12:56:38
通常不可能启用您的示例签名。
首先,您的签名者证书在默认情况下不是来自Adobe信任的CA,即CA证书既不在AATL上,也不在EUTL上。PDF阅读器不会将签名称为“启用LTV”,除非它以某种方式信任签名者。
此外,签名者证书没有任何AIA (授权信息访问)扩展,签名代码可以从中确定检索颁发者证书或吊销信息的位置。缺失的信息使得证书和撤销信息的自动检索成为可能。
因此,即使CA是可信的,启用自动LTV仍然需要自定义代码。
在这里的注释过程中(以及在与iText支持的通信过程中),事实证明所提供的示例签名并不具有代表性;另一方面,还有其他相关的边界条件,您最终会在用例中常规创建启用LTV的签名。
关于这个例程的细节可以在你的回答中找到。
发布于 2019-02-26 07:13:41
几个小时后,我想出了一个解决办法。要明确的是,Adobe有自己的信任库,所以您必须使用他们的证书之一,或者使用windows的信任库并相应地配置AC Reader并在那里添加根证书。如前所述,您应该将所有证书链都包含在PDF文档中。您可以访问我的GitHub项目,以查看一个工作示例,该示例对PDF文档进行签名,使用私钥对其进行加密,并启用ltv,使用iText 7使用来自ERMIS的timepstap。
制作启用ltv的示例:
private void ltvEnable(PdfSigner signer, ByteArrayOutputStream baos, OutputStream os, String name,
OcspClientBouncyCastle ocspClient, CrlClientOnline crlClient, CustomTSAClient tsc) {
ByteArrayInputStream signedPdfInput = new ByteArrayInputStream(baos.toByteArray());
try {
PdfReader pdfReader = new PdfReader(signedPdfInput);
PdfDocument document = new PdfDocument(pdfReader.setUnethicalReading(true), new PdfWriter(os),
new StampingProperties().useAppendMode());
LtvVerification ltvVerification = new LtvVerification(document);
ltvVerification.addVerification(name, ocspClient, crlClient, LtvVerification.CertificateOption.WHOLE_CHAIN,
LtvVerification.Level.OCSP_CRL, LtvVerification.CertificateInclusion.YES);
ltvVerification.merge();
document.getCatalog().getPdfObject().getAsDictionary(PdfName.DSS).getAsArray(PdfName.Certs)
.add(new PdfStream(
IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("HPARCA_CA.cer"))));
document.close();
pdfReader.close();
} catch (IOException | GeneralSecurityException e) {
LOG.error("Error while making signature ltv enabled");
}
}棘手的零件参数:
OCSPVerifier ocspVerifier = new OCSPVerifier(null, null);
OcspClientBouncyCastle ocspClient = new OcspClientBouncyCastle(ocspVerifier);
CrlClientOnline crlClient = new CrlClientOnline();https://stackoverflow.com/questions/54671892
复制相似问题