我正在使用 iTextSharp 5.5.2,我想用数字证书验证 XFA 文档。我的代码如下所示:
PdfReader reader = new PdfReader(path);
FileStream os = new FileStream(dest, FileMode.Create);
PdfStamper stamper = PdfStamper.createXmlSignature(reader, os);
XmlSignatureAppearance appearance = stamper.XmlSignatureAppearance;
appearance.SetXmlLocator(new XfaXmlLocator(stamper));
appearance.SetXpathConstructor(new XfaXpathConstructor(XfaXpathConstructor.XdpPackage.Datasets)); // Optional Line
appearance.SetCertificate(myCert);
var pk = Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(myCert.PrivateKey).Private;
IExternalSignature pks = new PrivateKeySignature(pk, DigestAlgorithms.SHA1);
MakeXmlSignature.SignXmlDSig(appearance, pks, GenerateKeyInfo(myChain));
不幸的是,当我在认证后打开PDF时,弹出“验证操作失败”。如果我注释掉与 XfaXpathConstructor 相关的可选行,我会收到带有 PDF 类型的横幅消息,上面写着“至少一个数据签名无效”。
无论哪种方式,我都无法打开签名面板,并且 PDF 无法成功认证......我错过了什么?