Certifying a PDF in C#

I’m having difficulty with certifying a PDF file. The code below is based upon some Aspose example code, but the loading of the PKCS7 instance (pskc) results in an instance, but the instance attributes are all default values and the pdf isn’t certified at the end of the program running.

The same certificate and password can be used to certify the pdf in Adobe Acrobat Pro.

Any help would be very much appreciated,

Darren

using Aspose.Pdf.Facades;
using Aspose.Pdf.Forms;

namespace CertifyRecreation
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Aspose.Pdf.License license = new Aspose.Pdf.License();

            license.SetLicense("Aspose.Total.NET.lic");

            Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("./Test.pdf");

            PKCS7 pskc = new PKCS7("./Exported.pfx", "**Password**");

            DocMDPSignature docMdpSignature = new DocMDPSignature(pskc, Aspose.Pdf.Forms.DocMDPAccessPermissions.NoChanges);

            PdfFileSignature signature = new PdfFileSignature(pdfDocument);

            signature.Certify(1,
                "Reason",
                "contact@outlook.com",
                "London",
                visible: true,
                new System.Drawing.Rectangle(100,100,100,100),
                docMdpSignature);
            
            pdfDocument.Save("./Preview/Test.pdf");
        }
    }
}

@DarrenWray

Would you please share your sample document along with other source files like PFX for our reference? Also, please share the screenshot of the issue. We will test the scenario in our environment and address it accordingly.

Unfortunately I can’t share the PFX as this is a production certificate, but I have attached one of the test documents, and the screenshot from Adobe.

Test Certified.pdf (21.7 KB)

image.png (40.7 KB)

You’ll notice that this document doesn’t include the certificate/signature banner expected.

HTH,

Darren

@DarrenWray

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54898

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

While looking for hints and solutions, I spotted this issue: https://forum.aspose.com/t/document-signing-with-certificate-and-timestamp-using-aspose-pdf-c/191038/5 - PDFNET-45987

This looks to be similar to the issue I’m reporting - Although I hope not as this issue was raised in Feb 2019 and looks to be unresolved from the last update! We’re hoping for a resolution in weeks, not years.

Darren.

@DarrenWray

The referred ticket is about signing a document using timestamp. Please note that issues are resolved on a first come first serve basis in free support model. Resolution time of the issue depends upon number of issues logged prior to it as well as the complexity and nature of the issue. Nevertheless, we have recorded your concerns and will surely consider them during ticket investigation. Please be patient and spare us some time.

We are sorry for the inconvenience.

A quick check-in on this issue, can you give me an update on progress, this issue is holding up a release of a new product.

Many thanks in advance,

Darren

@DarrenWray

We are afraid that we cannot share any ETA at the moment as the investigation of this ticket is not yet completed. We will surely let you know once we have some updates in this regard. We apologize for the inconvenience.

Hi - Any updates on this issue?

@DarrenWray

We are afraid that the ticket has not been yet resolved. We will surely inform you as soon as we make some progress towards ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any new on this issue?

@DarrenWray

Sadly, no updates are available at the moment about the ticket resolution as its investigation is not yet completed. We will surely inform you once we have some news about it fix ETA. Please spare us some time.

We apologize for the inconvenience caused.

@DarrenWray

We investigated the ticket. Below code would not produce expected results.

Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.NET.lic");

Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document("./Test.pdf");
PKCS7 pskc = new PKCS7("./Exported.pfx", "**Password**");
DocMDPSignature docMdpSignature = new DocMDPSignature(pskc, Aspose.Pdf.Forms.DocMDPAccessPermissions.NoChanges);
PdfFileSignature signature = new PdfFileSignature(pdfDocument);
signature.Certify(1,
    "Reason",
    "contact@outlook.com",
    "London",
    visible: true,
    new System.Drawing.Rectangle(100,100,100,100),
    docMdpSignature);

//pdfDocument.Save("./Preview/Test.pdf");//not correct
signature.Save("./Preview/Test.pdf");//correct

Instead, please use below correct code snippet:

var license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.NET.lic");

using (var signature = new PdfFileSignature())
{
    signature.BindPdf("./Test.pdf");
    var pskc = new PKCS7("./Exported.pfx", "**Password**");
    var docMdpSignature = new DocMDPSignature(pskc, Aspose.Pdf.Forms.DocMDPAccessPermissions.NoChanges);
    signature.Certify(1,
        "Reason",
        "contact@outlook.com",
        "London",
        visible: true,
        new System.Drawing.Rectangle(100, 100, 100, 100),
        docMdpSignature);
    signature.Save("./Preview/Test.pdf");
}