We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

IsDocumentModified on ValidateSignature is not working?

Hello,

When changing a signed PDF and validate this changed PDF document we get result that document is not modified while when we open the changed PDF in adobe reader we get the message that the PDF was modified after signing. Are we doing something wrong or is the IsDocumentModified property not working correctly?

We are using version 17.3.0.19 of Syncfusion.Pdf.Net.Core

Sample source code:
            //Create PDF
            using (PdfDocument document = new PdfDocument())
            {
                //Load certificate
                PdfCertificate pdfCert = null;
                using (FileStream certificateStream1 = new FileStream(@".pfx", FileMode.Open, FileAccess.Read))
                {
                    pdfCert = new PdfCertificate(certificateStream1, "");
                }

                //Add a page and text to the document.
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawString("Hello World!!!", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));

                //Add a digital signature.
                PdfSignature signature = new PdfSignature(document, page, pdfCert, "Signature");

                //Save to file system
                using (Stream tempPdfNameStream = new FileStream("file1.pdf", FileMode.Create))
                {
                    document.Save(tempPdfNameStream);
                }
                document.Close();
            }

            //Change PDF
            using (FileStream fileStream = new FileStream("file1.pdf", FileMode.Open))
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
            {
                loadedDocument.Pages[0].Graphics.DrawString("Change PDF!!!", new PdfStandardFont(PdfFontFamily.Helvetica, 30), PdfBrushes.Black, new Syncfusion.Drawing.PointF(100, 100));

                //Save doc to file system
                using (FileStream fileStream2 = new FileStream("fileChanged.pdf", FileMode.Create))
                {
                    loadedDocument.Save(fileStream2);
                }

                loadedDocument.Close();
            }

            //Validate
            using (FileStream fileStream = new FileStream("fileChanged.pdf", FileMode.Open))
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
            {
                var signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
                var res = signatureField.ValidateSignature();
                if (!res.IsDocumentModified) throw new Exception("The value of IsDocumentModified when validating the PDF document should be true and not false!");
            }

            Console.WriteLine("Everyting works like expected");
            Console.ReadLine();
        }

11 Replies

GK Gowthamraj Kumar Syncfusion Team October 28, 2019 08:23 AM UTC

Hi Jeffrey, 

Thank you for using Syncfusion products. 

Currently we are trying to reproduce the reported issue in our end and we will update the further details on October 30th 2019. 

Regards, 
Gowthamraj K 



SL Sowmiya Loganathan Syncfusion Team October 30, 2019 02:12 PM UTC

Hi Jeffrey,  

Sorry for the delay. Currently we are validating the issue which you have mentioned and we will update the further details by 1st November, 2019. 

Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team November 1, 2019 06:42 AM UTC

Hi Jeffrey, 

We can able to reproduce the reported issue “Signature validation is not proper for modified PDF documents”. We conformed it as a defect and patch for this issue fix will be available on 6th November 2019. 
 
Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team November 6, 2019 04:47 PM UTC

Hi Jeffrey, 

Sorry for the inconvenience caused. 

Due to complexities to handling incremental updated archive objects, still we are working on this with high priority. We will provide the patch on 13th November 2019. 
 
Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team November 13, 2019 12:24 PM UTC

Hi Jeffery,  

We have fixed the issue with “Signature validation is not proper for modified PDF documents” and the fix is included in our latest weekly NuGet package which is available in the following link.  

Kindly try this in your side and let us know if you need any further assistance. 
 
Regards, 
Sowmiya Loganathan 



JE Jeffrey November 24, 2019 08:22 PM UTC

Hello,

The sample application is working now with the latest weekly build but the following sample is not working:
            //Create PDF
            using (PdfDocument document = new PdfDocument())
            {
                //Add a page and text to the document.
                PdfPage page = document.Pages.Add();
                page.Graphics.DrawString("Hello World!!!", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));

                //Save to file system
                using (Stream tempPdfNameStream = new FileStream("file1.pdf", FileMode.Create))
                {
                    document.Save(tempPdfNameStream);
                }
                document.Close();
            }

            //Add signature to file
            using (FileStream fileStream = new FileStream("file1.pdf", FileMode.Open))
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
            {
                //Load certificate
                PdfCertificate pdfCert = null;
                using (FileStream certificateStream1 = new FileStream(@".pfx", FileMode.Open, FileAccess.Read))
                {
                    pdfCert = new PdfCertificate(certificateStream1, "");
                }

                //Add a digital signature.
                PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], pdfCert, "Signature");

                //Save doc to file system
                using (FileStream fileStream2 = new FileStream("file2.pdf", FileMode.Create))
                {
                    loadedDocument.Save(fileStream2);
                }

                loadedDocument.Close();
            }


            //Change PDF after signature
            using (FileStream fileStream = new FileStream("file2.pdf", FileMode.Open))
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
            {
                loadedDocument.Pages[0].Graphics.DrawString("Change PDF!!!", new PdfStandardFont(PdfFontFamily.Helvetica, 30), PdfBrushes.Black, new Syncfusion.Drawing.PointF(100, 100));

                //Save doc to file system
                using (FileStream fileStream2 = new FileStream("fileChanged.pdf", FileMode.Create))
                {
                    loadedDocument.Save(fileStream2);
                }

                loadedDocument.Close();
            }

            //Validate
            using (FileStream fileStream = new FileStream("fileChanged.pdf", FileMode.Open))
            using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream))
            {
                var signatureField = loadedDocument.Form.Fields[0] as PdfLoadedSignatureField;
                var res = signatureField.ValidateSignature();
                if (!res.IsDocumentModified) throw new Exception("The value of IsDocumentModified when validating the PDF document should be true and not false!");
            }

            Console.WriteLine("Everyting works like expected");
            Console.ReadLine();

Regards,
Jeffrey


SL Sowmiya Loganathan Syncfusion Team November 25, 2019 09:01 AM UTC

Hi Jeffrey, 

We were able to reproduce the mentioned issue and suspect that this to a defect. Currently we are validating the same and will update the further details by 27th November, 2019.  

Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team November 28, 2019 12:29 PM UTC

Hi Jeffery, 

Thank you for your patience.  

Thanks for your patience. We have confirmed that the reported issue with “IsDocumentModified on ValidateSignature is not working” is defect. And we are working on this with high priority. The patch for this issue fix will be available on or before 04th December 2019. 
 
Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team December 4, 2019 09:30 AM UTC

Hi Jeffery, 
 
We have fixed the reported issue and the fix will included in our upcoming weekly NuGet package release which is available on 10th December 2019. 
 
Regards, 
Sowmiya Loganathan 



SL Sowmiya Loganathan Syncfusion Team December 10, 2019 10:58 AM UTC

Hi Jeffrey, 
 
We have include the code changes for the reported issue “IsDocumentModified on ValidateSignature is not working” in weekly NuGet release. Please find the download link from below, 
 
Regards, 
Sowmiya Loganathan  



SL Sowmiya Loganathan Syncfusion Team December 19, 2019 12:29 PM UTC

Hi Jeffery, 
 
We have included the “Validating digital signature based on the incremental updates in our Essential Studio 2019 Volume 4 Release v17.4.0.39. We are glad to announce that it is rolled out and is available for download under the following link. 
 
Please find the documentation link from below, 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
 
Regards, 
Sowmiya Loganathan        


Loader.
Live Chat Icon For mobile
Up arrow icon