views:

3233

answers:

5

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

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 :)

+6  A: 

The open source iTextSharp library will allow you to do this. Here's a post explaining 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)

Darin Dimitrov
+4  A: 

Proper PDF signing is a very sophisticated 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 PDFBlackbox.

Eugene Mayevski 'EldoS Corp
Thank you for the tip ;) I did not knew PDFBlackBox
Sergio
+1  A: 

Take a look at this article on CodeProject

Corne
+1  A: 

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

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.

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

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

AffineMesh94464
A: 

Lost my first answer. May want to give DocQ a try to link text They 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.

I need the users to be able to use their own certificates. Got this working now using iTextSharp
Sergio