C# 对 PDF 文件进行数字签名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/378247/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 01:13:13  来源:igfitidea点击:

Digitally sign PDF files

c#pdfdigital-signature

提问by Sergio

I have a digital certificate that identifies an user. I need to use it to Digitally sign pdf files.

我有一个识别用户的数字证书。我需要用它来对 pdf 文件进行数字签名。

Does anyone have an example that does not uses a third party component? I need to get this done but it would be nice to fully understand how things are done.

有没有人有一个不使用第三方组件的例子?我需要完成这项工作,但最好能完全了解事情是如何完成的。

C# Examples please :)

C#示例请:)

采纳答案by Darin Dimitrov

The open source iTextSharplibrary will allow you to do this. Here's a postexplaining how to digitally sign a pdf file. If you don't want to use a third party library then you can implement it yourself but it could be a tough task -> you can start by reading the pdf specification(8.6MB)

开源iTextSharp库将允许您执行此操作。这是一篇解释如何对 pdf 文件进行数字签名的帖子。如果您不想使用第三方库,那么您可以自己实现它,但这可能是一项艰巨的任务 -> 您可以从阅读pdf 规范(8.6MB) 开始

回答by Eugene Mayevski 'Callback

Proper PDF signing is a verysophisticated task. There exist a number of files that don't conform to the PDF specification (broken xrefs etc) and your code must handle all of them. Then various Acrobat versions treat certain things in signed fields differently. So if you need to do the task (rather than study how it works) you should rely on third-party solution, such as our PDFBlackboxcomponents.

正确的 PDF 签名是一项非常复杂的任务。存在许多不符合 PDF 规范(损坏的外部参照等)的文件,您的代码必须处理所有这些文件。然后各种 Acrobat 版本以不同的方式处理签名字段中的某些内容。因此,如果您需要完成任务(而不是研究它是如何工作的),您应该依赖第三方解决方案,例如我们的PDFBlackbox组件。

回答by AffineMesh

Digitally signing a PDF document without using a third-party component entails a great deal of work and is generally best avoided.

在不使用第三方组件的情况下对 PDF 文档进行数字签名需要大量工作,通常最好避免。

Components do all the hard work for you, so you don't have to. You should find there are some excellent free PDF components available that will suit your needs.

组件会为您完成所有繁重的工作,因此您不必这样做。您应该会发现有一些优秀的免费 PDF 组件可以满足您的需求。

The following example written in C# shows how simple it is to digitally sign a PDF document using ABCpdf:

以下用 C# 编写的示例显示了使用 ABCpdf 对 PDF 文档进行数字签名是多么简单:

Doc theDoc = new Doc();
theDoc.Read(Server.MapPath("../Rez/Authorization.pdf"));
Signature theSig = (Signature)theDoc.Form["Signature"];
theSig.Location = "Washington";
theSig.Reason = "Schedule Agreed";
theSig.Sign(Server.MapPath("../Rez/JohnSmith.pfx"), "111111");
theDoc.Save(Server.MapPath("Signed.pdf"));

Source: ABCpdf documentation - Sign method

来源:ABCpdf 文档 - 签名方法

回答by user337658

Lost my first answer. May want to give DocQ a try to link textThey have their own cert and can do this for you for free/cheap to seal and encrypt PDFs. They also have an API you can use.

失去了我的第一个答案。可能想尝试 DocQ链接文本他们有自己的证书,可以免费/便宜地为您执行此操作以密封和加密 PDF。他们还有一个您可以使用的 API。