數字簽名的端口對於iText 7的白皮書代碼示例可以在iText 7 Java samples github repository子文件夾/publications/signatures/(例如)中找到。從簡單C2_01_SignHelloWorld示例節選:
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);
}
來源
2016-12-15 15:49:08
mkl
你有沒有看看[iText的7 Java範例的GitHub庫(https://github.com/itext/i7js-samples)?在子文件夾[/publications/signatures/](https://github.com/itext/i7js-samples/tree/develop/publications/signatures)中,它包含了移植到iText 7的白皮書示例。 – mkl
非常感謝。如果你可以在下面寫出答案,那麼請將它標記爲:) –