首页 > 解决方案 > IText:无法设置 PdfSignatureAppearance 的 СryptoDictionary 属性

问题描述

有一个使用 iTextSharp 的代码:

PdfReader reader = new PdfReader(document);
PdfStamper st = PdfStamper.CreateSignature(reader, new FileStream(document + "_signed.pdf", FileMode.Create, FileAccess.Write), '\0');                        
PdfSignatureAppearance sap = st.SignatureAppearance;

// something

PdfSignature dic = new PdfSignature(filterName, PdfName.ADBE_PKCS7_DETACHED);
sap.CryptoDictionary = dic;

我需要使用 iText7 编写它:

PdfReader reader = new PdfReader(@"C:\Users\RakuVIu\Documents\rozha.pdf");
PdfSigner signer = new PdfSigner(reader, new FileStream(document + "_signed.pdf", FileMode.Create), new StampingProperties());
PdfSignatureAppearance appearance = signer.GetSignatureAppearance();

// something

PdfSignature signature = new PdfSignature(filterName, PdfName.Adbe_pkcs7_detached);
appearance.SetCryptoDictionary(signature); // no such method!

所以,我不能设置 CryptoDictionary 属性,因为没有方法或属性可以做到这一点。

标签: c#itext

解决方案


iText 7 签名 API 试图隐藏自 5.3.x 签名 API 大修以来不应再使用的实现细节,而签名字典就是这样一个细节。

关于 5.3.x 版本中引入的签名 API 的详细信息,请阅读iText 数字签名白皮书。那里的 Java 示例已移植到 C#,可以在此处访问。


推荐阅读