java itext 数字签名,使用IText 7将数字签名添加到PDF

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.

解决方案

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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值