Change Subject Name with Digital Signature

We are using the following basic code for signing the PDF:

ExternalSignature externalSignature = new ExternalSignature(certificate);
externalSignature.CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance {
    ShowContactInfo = false,
    ShowLocation = false,
    ShowReason = false
};
string inFile = System.IO.Path.Combine("Foo.pdf");
string outFile = System.IO.Path.Combine("FooSigned.pdf");
using (Document document = new Document(inFile))
{
    using (PdfFileSignature signature = new PdfFileSignature(document))
    {
        signature.Sign(1, true, new System.Drawing.Rectangle(100, 100, 200, 100), externalSignature);
        // Save output PDF file
        signature.Save(outFile);
    }
}

This adds the digital certificate with the default text: "Digitally signed by ‘{Subject Name}’
However, the subject name on the certificate is not concise so we need to change/regex/format the subject name to be more readable.
But there is no API to change the subject name or the value of the text.

Any solution or an API to resolve this would be helpful.

Thanks

@jajohal

Could you please share the input PDF, problematic output PDF and expected output PDF along with certificate file?

Also, please share the complete working code example here for testing. We will investigate the issue and provide you more information on it.

Hi,

Apologies for the late response, full code:

Import

using Aspose.Pdf;
using Aspose.Pdf.Facades;
using Aspose.Pdf.Forms;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography;
using System.IO;

Setup


// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
try
{
    // Set license
    license.SetLicense("total.lic");
}
catch (Exception)
{
    // something went wrong
    throw;
}

var rawCert  = File.ReadAllText("C:\\Dev\\cert.pfx");

var certificate = new X509Certificate2(
    Convert.FromBase64String(rawCert), 
    "",
    X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.UserKeySet);

ExternalSignature externalSignature = new ExternalSignature(certificate);
externalSignature.CustomAppearance = new Aspose.Pdf.Forms.SignatureCustomAppearance { 
    ShowContactInfo = false,
    ShowLocation = false,
    ShowReason = false
};

Work

string inFile = System.IO.Path.Combine("Foo.pdf");
string outFile = System.IO.Path.Combine("FooSigned.pdf");
using (Document document = new Document(inFile))
{
    using (PdfFileSignature signature = new PdfFileSignature(document))
    {
        signature.Sign(1, true, new System.Drawing.Rectangle(100, 100, 200, 100), externalSignature);
        // Save output PDF file
        signature.Save(outFile);
    }
}

Cert File:
cert.zip (5.1 KB)

@jajohal

We have logged your requirement in our issue tracking system as PDFNET-52671. We will inform you once there is an update available on it.

We apologize for your inconvenience.

Hi,

We did some additional digging and found the following:
Seems that the certificate has x500 Subject string (IETF PKIX (latest version RFC 5280))
Aspose PDF library prints the entire Subject string.
However, we only need the Common Name (CN) printed.

X500DistinguishedName Class (System.Security.Cryptography.X509Certificates) | Microsoft Learn

Also, could you let us know by when can this be done? Or what we can do to accelerate this?

@jajohal

We have logged the shared detail in our issue tracking system.

Currently, your issue is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

@tahir.manzoor
Is there any update on this?
We have a deadline approaching for this Issue in our solution.

@jajohal

The issue has been logged under free support model and we are afraid that it has not been yet resolved. We will surely resolve and fix it on a first come first serve basis and let you know via this forum thread once we have some updates in this regard. Please spare us some time.

We are sorry for the inconvenience.