Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sat Feb 13, 2016 10:00 am

Hi,

We're creating an application that needs to electronically sign a PDF using an electronic ID card that has the private key embedded in the card and cannot be downloaded. In order to sign using this card, one is supposed to create a hash of the to-be-secured object (the pdf in this case), send this to the card to sign it with its private key and retrieve the result. This result should be placed in the PDF as an electronic signature.

I was wondering if this is possible with Spire.PDF? I searched through the SDK but couldn't seem to find a way to do this. Does Spire.PDF only support signatures based on a certificate with both public and private key embedded within? Or is there an other way?

Thanks.

DTDF
 
Posts: 2
Joined: Sat Feb 13, 2016 9:34 am

Sun Feb 14, 2016 8:12 am

Hi,

Thanks for your posting.
After you get .pfx files that corresponding electronic IDs generate, please try the following code to add the signature into PDF.
Code: Select all
            PdfDocument doc = new PdfDocument(@"..\..\11111.pdf");
            PdfPageBase page = doc.Pages.Add();
            PdfCertificate cert = new PdfCertificate(@"..\..\Demo.pfx", "e-iceblue");

            var signature = new PdfSignature(doc,page, cert, "Requestd1");
            signature.Bounds = new RectangleF(new PointF(200, 200), new SizeF(300, 300));
            signature.IsTag = true;
            signature.DigitalSignerLable = "Digitally signed by";
            signature.DigitalSigner = "Harry Hu for Test";
            signature.DistinguishedName = "DN:";
            signature.LocationInfoLabel = "Location:";
            signature.LocationInfo = "London";
            signature.ReasonLabel = "Reason: ";
            signature.Reason = "Le document est certifie";
            signature.DateLabel = "Date: ";
            signature.Date = DateTime.Now;
            signature.ContactInfoLabel = "Contact: ";
            signature.ContactInfo = "123456789";
            signature.Certificated = false;
            signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
            signature.IsConfiguerGraphicFilledBounds = false;
            doc.CompressionLevel = PdfCompressionLevel.Best;
            doc.SaveToFile(output);
         

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Tue Feb 16, 2016 1:44 pm

Hi Amy,

Thank you for the response. I'm a bit confused however. I was working under the assumption that the PdfCertificate that one should provide to Spire.PDF contains the public and private key. Spire.PDF would then calculate the relevant hash data from the PDF, "sign" it with the private key and add the necessary data to the PDF.
Is this not true? Does the to-be-provided certificate contain a signed version of the PDF hash instead?
In that case, is there a way in Spire.PDF to get the correct hash data so I can send this to the electronic ID?

Thanks.

DTDF
 
Posts: 2
Joined: Sat Feb 13, 2016 9:34 am

Wed Feb 17, 2016 3:58 am

Hi,

Thanks for your inquiry.
Signed public key is not provided and each signed public key is different, and it is able to be obtained in the program.
Sorry that there is no way to get hash data at present.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2774
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF