使用IText 7将数字签名添加到PDF [英] Add Digital Signature to a PDF using IText 7
问题描述
对于IText 5,添加数字签名非常容易. 其文档的链接是: http://developers.itextpdf. com/examples/security/digital-signatures-white-paper/digital-signatures-chapter-2
For IText 5, adding digital signature was fairly easy. The link for its documentation is: http://developers.itextpdf.com/examples/security/digital-signatures-white-paper/digital-signatures-chapter-2
有人可以在ITEXT 7中共享指向文档的链接吗? 我尝试了各种方法都无济于事.找不到在线任何链接.我可以取消签名并检查签名,但是不能添加它.
Can someone share the link to documentation for doing so in ITEXT 7? I have tried various ways to no avail. Could not find any links online. I can unsign and check signature, but can't add it.
推荐答案
iText 7的数字签名白皮书代码示例的端口可以在 iText 7 Java签名示例github存储库测试源包 C2_01_SignHelloWorld 示例:
Ports of the Digital Signatures Whitepaper code examples to iText 7 can be found in the iText 7 Java signature samples github repository test sources package com.itextpdf.samples.signatures, e.g. an excerpt from the simple C2_01_SignHelloWorld example:
public void sign(String src, String dest,
Certificate[] chain,
PrivateKey pk, String digestAlgorithm, String provider,
PdfSigner.CryptoStandard subfilter,
String reason, String location)
throws GeneralSecurityException, IOException {
// Creating the reader and the signer
PdfReader reader = new PdfReader(src);
PdfSigner signer = new PdfSigner(reader, new FileOutputStream(dest), false);
// Creating the appearance
PdfSignatureAppearance appearance = signer.getSignatureAppearance()
.setReason(reason)
.setLocation(location)
.setReuseAppearance(false);
Rectangle rect = new Rectangle(36, 648, 200, 100);
appearance
.setPageRect(rect)
.setPageNumber(1);
signer.setFieldName("sig");
// Creating the signature
IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, provider);
IExternalDigest digest = new BouncyCastleDigest();
signer.signDetached(digest, pks, chain, null, null, null, 0, subfilter);
}
这篇关于使用IText 7将数字签名添加到PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!