Signature is invalid when Sign and SetPrivilege

Hi,

I got Signature is invalid when applying both certified signature and PdfFileSecurity.SetPriviledge

When adding signature with DocMDPAccessPermissions.NoChanges and then applying PdfFileSecurity.SetPriviledge (DocumentPrivilege.Print), the pdf gets “Signature is invalid. There are errors in the formatting or information containted in this signature (support information: SignDict/Contents illegal data)”

When applying PdfFileSecurity.SetPriviledge (DocumentPrivilege.Print) and then adding signature with DocMDPAccessPermissions.NoChanges, the pdf gets “Signature is invalid. There are errors in the formatting or information containted in this signature (The signature byte range is invalid)”

Is it possible to apply both signature and SetPriviledge?

Thank you
AsposePDF Sign and SetPriviledge.png (40.9 KB)

@LISHELP

Thank you for contacting support.

We would like to share with you that a Signed document can not be modified because modifications make the Signatures invalid. So, please set desired privileges and then sign the document. Kindly try using below code snippet in your environment and then share your kind feedback with us.

        Document document = new Document(dataDir + "input.pdf");
        //Set privileges for the document
        DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;
        
        //Apply the print privilege
        privilege.AllowPrint = true;

        //Set the desired privileges
        PdfFileSecurity fileSecurity = new PdfFileSecurity(document);
        fileSecurity.SetPrivilege(privilege);

        //Save the signed and encrypted version of the document
        document.Save(dataDir + "Encrypted_18.4" + ".pdf");
            
        //Sign
        string inFile = dataDir + "Encrypted_18.4" + ".pdf";
        PdfFileSignature pdfSign = new PdfFileSignature();
        pdfSign.BindPdf(inFile);
        pdfSign.SignatureAppearance = (@"D:\Files\" + "Sign.png");
        Aspose.Pdf.Forms.PKCS7Detached pkcs7 = new Aspose.Pdf.Forms.PKCS7Detached(@"D:\Files\test.pfx", "test");
        pdfSign.Sign(1, "ABC", "1234", "XYZ", true, new System.Drawing.Rectangle(100, 100, 150, 50), pkcs7);
        pdfSign.Save(dataDir + "Signed_" + "18.4" + ".pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Dear Farhan,

This is helpful.
However, I would like to check if we can use DocMDPSignature class for the signature, and use Certify instead of Sign as this would show in the PDF document “Certified by”, while with Sign, the PDF document would shows “Signed by”
Below is my code and the pdf document show “Certified by”, however it also says “Signature is invalid”.

        string dataDir = "C:\\temp\\";
        Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "input.pdf");
        //Set privileges for the document
        DocumentPrivilege privilege = DocumentPrivilege.ForbidAll;

        //Apply the print privilege
        privilege.AllowPrint = true;

        //Set the desired privileges
        PdfFileSecurity fileSecurity = new PdfFileSecurity(document);
        fileSecurity.SetPrivilege(privilege);

        //Save the signed and encrypted version of the document
        document.Save(dataDir + "Encrypted_18.4" + ".pdf");

        //Sign
        string inFile = dataDir + "Encrypted_18.4" + ".pdf";

        PdfFileSignature pdfSign = new PdfFileSignature();
        pdfSign.BindPdf(inFile);

        PKCS7 pkcs = new PKCS7("C:\\temp\\LanLocal.pfx", "WayPoint");
        DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.NoChanges);
        System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, 100, 100);
        pdfSign.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
        pdfSign.Save(dataDir + "Signed_" + "18.4" + ".pdf");

Thank you

@LISHELP

Would you please share your source and generated PDF file along with the PFX file that you are using for this certification. Attachment are accessible to topic owner and our staff only, thus share the requested data with us as a single ZIP file so that we may try to reproduce and investigate the scenario in our environment.

Hi Farhan,

Per your request, attached is an console solution/project with pfx file, input, output pdf file.

Thank you for your help and please let me know if you need any additional information.

ApposeCerifiedSignature.zip (646.6 KB)

Seems the zip file failed to upload when I have the Aspose.Pdf dll attached together in the zip file. I removed the Aspose.Pdf dll from the zipfile. Please add it back when opening the project, I am using Aspose.Pdf_9.2.1.

Thank you

@LISHELP

Thank you for sharing requested data.

We have worked with the data shared by you and have been able to reproduce the issue while certifying generated document. A ticket with ID PDFNET-44579 has been logged in our issue management system for further investigation and resolution. The issue ID has been linked with this thread so that you will receive notification as soon as the issue is resolved.

We are sorry for the inconvenience.

Thank you Farhan.

Just to set our expectation and help our planning, how long usually it take to revolve this kind of issue/ticket?

@LISHELP

The issue reported by you has just been logged in our issue management system. Currently it is pending owing to previously logged issues. It will be scheduled on its due turn that can take several months. We appreciate your patience and comprehension in this regard.

However, we also offer Paid Support, where issues are used to be investigated with higher priority. Our customers, who have paid support subscription, report their issue there which are meant to be investigated urgently. In case your reported issue is a blocker, you may please consider subscribing for Paid Support. For further information, please visit Paid Support FAQ.

Thank you Farhan for the information

The issues you have found earlier (filed as PDFNET-44579) have been fixed in Aspose.PDF for .NET 22.3.