Invalid Digital Signatures

Hello,

I'm able to successfully place a digital signature onto a PDF; however, Adobe and DocuSign signature validator both are telling me that the signature is invalid.  The system I am building allows the user to select where a signature goes, email someone to sign the PDF, then that user can then select their signature, click where the previous user placed the signature, and sign the document.  All of that works great, but placing the actual signature is proving to be a challenge.

The following code is in a foreach loop of the documents within the signing package and a foreach loop for the recipients within the package.  After I loop through the recipients, I save the document and move to the next document.  As I said, this works, but the signature is invalid.  If anyone could tell me what I'm doing wrong I would appreciate it!!

-------------------------------------------------------------------------------------------------------------------

Adobe Message

Signature contains incorrect, unrecognized, corrupted or suspicious data.

Support Information: SigDict /Contents illegal data

-------------------------------------------------------------------------------------------------------------------

Signing Code

Stream pfxStream = File.OpenRead("SigningCert.pfx");

PdfCertificate certificate = new PdfCertificate(pfxStream, "password");

var page = loadedDocument.Pages[stamp.PageNumber.Value];

PdfSignature signature = new PdfSignature(loadedDocument, page, certificate, "Signature " + i.ToString());

PdfSignatureSettings settings = signature.Settings;

settings.CryptographicStandard = CryptographicStandard.CADES;

signature.Bounds = new Syncfusion.Drawing.RectangleF(new Syncfusion.Drawing.PointF(stamp.Rect.X.Value, stamp.Rect.Y.Value), selectedSignature.PhysicalDimension);

signature.EnableValidationAppearance = true;

signature.ContactInfo = recipient.EmailAddress;

signature.LocationInfo = "USA";

signature.Reason = "Signature Request";

signature.Appearance.Normal.Graphics.DrawImage(selectedSignature, 0, 0, selectedSignature.Width, selectedSignature.Height);


1 Reply

GK Gowthamraj Kumar Syncfusion Team September 17, 2021 01:58 PM UTC

Hi Tim, 
 
Thank you for contacting Syncfusion support. 
 
We can sign PDF document in multiple pages with the same signature without breaking the existing signature. We have created a simple sample with our test document and attached the sample and output document for your reference. Please try the below sample on your end and let us know the result.

 
 
Please refer the below documentation link, 
   
Note: To achieve this requirement, we need to disable the FieldAutoNaming property and also we need to provide the same signature name while creating a PdfSignature.   
 
Please find the code to achieve this requirement below, 
FileStream file = new FileStream("../../../Data/Barcode.pdf", FileMode.Open, FileAccess.Read); 
              
            //Load PDF document  
            PdfLoadedDocument loadedDocument = new PdfLoadedDocument(file); 
            
            loadedDocument.Form.FieldAutoNaming = false; 
 
            for (int i = 0; i < loadedDocument.Pages.Count; i++) 
            { 
                //Get Graphics object for put digital signature  
                PdfGraphics graphics = loadedDocument.Pages[i].Graphics; 
                FileStream Pfxfile = new FileStream("../../../Data/PDF.pfx", FileMode.Open, FileAccess.Read); 
 
                PdfCertificate certificate = new PdfCertificate(Pfxfile, "syncfusion"); 
 
                //Create a signature with loaded digital ID.  
                PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[i], certificate, "DigitalSignature"); 
 
                PdfSignatureSettings settings = signature.Settings; 
                ////Changing the digital signature standard and hashing algorithm.  
                signature.Settings.CryptographicStandard = CryptographicStandard.CADES; 
              
                FileStream imagefile = new FileStream("../../../Data/logo.png", FileMode.Open, FileAccess.Read); 
 
                //Draw image 
                PdfBitmap signatureImage = new PdfBitmap(imagefile); 
      
                //Draws the signature   
                PdfPen pen = new PdfPen(Color.Black); 
                graphics.DrawRectangle(pen, PdfBrushes.White, signature.Bounds); 
                signature.Bounds = new Syncfusion.Drawing.RectangleF(new Syncfusion.Drawing.PointF(0,0), signatureImage.PhysicalDimension); 
 
                signature.EnableValidationAppearance = true; 
 
                signature.ContactInfo = "Syncfusion"; 
 
                signature.LocationInfo = "USA"; 
 
                signature.Reason = "Signature Request"; 
 
                signature.Appearance.Normal.Graphics.DrawImage(signatureImage, 0, 0, signatureImage.Width, signatureImage.Height); 
            } 
            MemoryStream str = new MemoryStream(); 
            loadedDocument.Save(str); 
            loadedDocument.Close(true); 
            File.WriteAllBytes("../../../Output.pdf", str.ToArray()); 
 
Please try the above suggestion on your end and let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon