c# - 如何使用 ItextSharp 检索数字签名信息(名称、日期...)

标签 c# .net pdf itext digital-signature

我有一个由 2 个人(开斋节)签名的 PDF。

我正在尝试检索此信息,但目前无法检索。

这是我目前所拥有的:

namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string workingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string inputFile = Path.Combine(workingFolder, "Tax Return.pdf");            

                PdfReader reader = new PdfReader(inputFile);

                Console.ReadLine();
            }
        }
    }

如果我在运行时检查“阅读器”,我可以看到 AcroForm 有 2 个指向签名的字段,但我看不到有关这些签名的任何特定信息。

最佳答案

简短示例:

StringBuilder sb = new StringBuilder();
PdfReader reader = new PdfReader(pdf);
AcroFields af = reader.AcroFields;
ArrayList  names = af.GetSignatureNames();
for (int i = 0; i < names.Count; ++i) {
  String name = (string)names[i];
  PdfPKCS7 pk = af.VerifySignature(name);
  sb.AppendFormat("Signature field name: {0}\n", name);
  sb.AppendFormat("Signature signer name: {0}\n", pk.SignName);
  sb.AppendFormat("Signature date: {0}\n", pk.SignDate);
  sb.AppendFormat("Signature country: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("C")
  );
  sb.AppendFormat("Signature organization: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("O")
  );
  sb.AppendFormat("Signature unit: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("OU")
  );
}

关于c# - 如何使用 ItextSharp 检索数字签名信息(名称、日期...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823240/

相关文章:

c# - 将 double 序列化为 JSON 时的小数精度为零

c# - TextBox没有BorderStyle属性

c# - 文本框控件更新后 Bindingsource 将不会更新

.net - jQuery getJson() 无法在 ASP.NET MVC 中使用

c# - Microsoft.Office.Tools.Excel 丢失

html - 使用 CSS 仅在最后一页删除页脚

PDF 间接引用和增量更新

c# - 如何在 DDD 实体中表示引用

ios - UIWebView 从 NSString 加载 PDF 字节

c# - 通过服务或直接访问存储库?