简体   繁体   中英

The "SignName" property of class PdfPKCS7 always return null in Itext 5.5.13.2 using the C#

I signed the pdf successfully and also verified the pdf successfully but the " SignName " property of class PdfPKCS7 always returns null .

I don't know why? Am I missing something during the pdf signing process or verification process?

//res.SignName always returns null.

validite = "Validated: " + res.SignName;

Pdf signing code see here: "Invalid algorithm specified" when pdf signing with Itext 5.5.13.2

and Verification Code is given below.

private void Button1_Click(object sender, EventArgs e)
{
    PdfReader reader;
    reader = new PdfReader(pdfFilePath.Text);
    try
    {
        AcroFields acf = reader.AcroFields();
        List<string> sgnoms = acf.GetSignatureNames();
        List<string> sgnoms2 = acf.GetBlankSignatureNames();
        Org.BouncyCastle.X509.X509Certificate cert;

        if (sgnoms.Count > 0)
        {
            foreach (object obj in sgnoms)
            {
                PdfPKCS7 res = acf.VerifySignature(obj.ToString());
                string validite = "Not Validate";
                DateTime cal = res.SignDate;
                if (res.SigningCertificate.IsValid(DateTime.Now) && res.Verify())
                   //res.SignName` Always returns null          
                   validite = "Validated : " + res.SignName;
                res = null;
                validite = null;
                cal = default(DateTime);                
            }
        }
        else
            throw new Exception("Document not sign!");

        reader = null;
        acf = null;
        sgnoms = null;
        sgnoms2 = null;
    }
    catch (Exception ex)
    {
    }
}

Is any alternative to get the Signer Name? Or anything missing in the code?

Please check it, Unbale to get the reason. Am I missing something during the pdf signing process? or Am I missing something during the pdf verification process?

Any ideas, working code and suggestions are welcome.

Thanks in advance.

The SignName property is the value of the Name entry of the signature dictionary. This entry is specified as:

Key Type Value
Name text string (Optional) The name of the person or authority signing the document. This value should be used only when it is not possible to extract the name from the signature.
EXAMPLE 1 From the certificate of the signer.

(ISO 32000-1, Table 252 – Entries in a signature dictionary)

This entry is optional, so the value you retrieve may well be null.

There is also a hint where you can look for the signer name here: in the signer certificate, Thus, consider inspecting the SigningCertificate property of your PdfPKCS7 object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM