简体   繁体   中英

How to save digital signature image or its byte[] in to database using itextsharp?

I am working on a pdf form and it contains a digital signature field. When we click on the digital signature field it asks for selecting a valid signature and after that it asks to save the file. My requirement is to save the digital signature to db based on the user id. I have a button in the pdf form , when we click on that button it redirects to handler file. This handler class get the data in the form httpcontext. In this case, after submit the button all other fileds data reach the handler except the digital signature field.

Is there any way to read the digital signature data to the handler ?

Thanks in advance.

First of all,

This handler class get the data in the form httpcontext. In this case, after submit the button all other fileds data reach the handler except the digital signature field.

This sounds like your PDF form submit action has the ExportFormat flag set. In this case digital signatures are not transmitted. You either have to set the SubmitPDF flag instead which causes the whole document with all changes to be submitted, or neither of those two flags (causing a FDF to be submitted) but instead the IncludeAppendSaves flag which causes the submitted FDF file to include the contents of all incremental updates to the underlying PDF document.

On the server side the full PDF is needed to continue with iText high level methods, for SubmitPDF that is exactly what you get, for IncludeAppendSaves you have to combine the original PDF with the incremental updates.

Now you can extract the signature data.

As you use the name iTextSharp and the tag, I assume you are using a 5.5.x version, not a 7.x version of iText for .Net.

Whenever you have a PDF, you can determine its signed signature fields using the GetSignatureNames() method of the AcroFields property of a PdfReader you used to read the file:

PdfReader reader = new PdfReader(path);
AcroFields fields = reader.AcroFields;
List<String> names = fields.GetSignatureNames();

For each such field you can retrieve the actual signature bytes from the Contents entry of the signature dictionary of the field:

byte[] signatureBytes = fields.GetSignatureDictionary(name).GetAsString(PdfName.CONTENTS).GetOriginalBytes();

In case of an interoperable ISO 32000-1 or a PAdES/ISO 32000-2 signature these bytes will either contain a fairly naked PKCS#1 signature structure or a CMS signature container. To really make sense out of these structures, you usually also need additional information from the signature dictionary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM