【问题标题】:How to show digital signature VALUE in signature appearance of PDF file with iTextSharp如何使用 iTextSharp 在 PDF 文件的签名外观中显示数字签名 VALUE
【发布时间】:2015-04-27 10:50:22
【问题描述】:

是否可以在签名文档时在签名外观中附加数字签名VALUE,因为我正在使用这部分代码

PdfFilename = txtFile.Text + "\\" + (string)chkLista.Items[i];
DestPdfFilename = txtFile.Text + "\\" + (string)chkLista.Items[i] + "-signed.pdf";

Org.BouncyCastle.X509.X509CertificateParser cp = new Org.BouncyCastle.X509.X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { cp.ReadCertificate(cert.RawData) };
IExternalSignature externalSignature = new X509Certificate2Signature(cert, "SHA-256");
PdfReader pdfReader = new PdfReader(PdfFilename);
FileStream signedPdf = new FileStream(DestPdfFilename, FileMode.Create);  //the output pdf file
PdfStamper pdfStamper = PdfStamper.CreateSignature(pdfReader, signedPdf, '\0');
PdfSignatureAppearance signatureAppearance = pdfStamper.SignatureAppearance;

signatureAppearance.SignatureRenderingMode = PdfSignatureAppearance.RenderingMode.DESCRIPTION;
signatureAppearance.SetVisibleSignature(new iTextSharp.text.Rectangle(436, 700, 564, 750), 1, "sig");

MakeSignature.SignDetached(signatureAppearance, externalSignature, chain, null, null, null, 0, CryptoStandard.CMS);

但在 PDF 中,它仅显示仅填充有以下数据的矩形:数字签名者:...和日期:...

除此之外,我也想在 Base64 中显示数字签名值!

【问题讨论】:

    标签: c# itextsharp digital-signature


    【解决方案1】:

    如果我正确理解了 OP,那么任务就是将实际签名值字节的 base64 表示显示为签名字段外观。

    这是不可能的。

    原因是签名字段的外观是签名字节范围的一部分:

    (外观在示例的第一或第三部分中的某处定义。)

    因此,必须在创建签名值之前知道外观。因此,在字段外观中无法完全表示该值。

    更多背景请阅读this answer

    话虽如此,您可能会尝试通过在 PDF 中添加 JavaScript 来作弊,这会在 显示时间改变签名字段的外观。但是,这种方法有两个缺点:

    • 并非所有 PDF 查看器都支持 JavaScript。
    • Adobe Reader 和 Acrobat,也支持 JavaScript 的主要 PDF 查看器,会识别出这种外观变化并指示签名已损坏。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 1970-01-01
      • 2018-11-17
      相关资源
      最近更新 更多