0

I need help.

I am writing a PDF digitally signed API application and am using PdfStamper. But when I run it, I get an error and I can't find the cause of the error.

Help me! Thank you!

Below is the code that I wrote:

 public void doSign(String src, String dest, float llx, float lly, float urx, float ury, int NumPage, String FieldName)
        {
            try
            {
                PdfReader reader = new PdfReader(src);
                FileStream os = new FileStream(dest, FileMode.Create);
                PdfStamper stamper = PdfStamper.CreateSignature(reader, os, '\0');
                Byte[] CertificateValue = SignAPI.GetCertificate();
                ICollection<X509Certificate> chain = this.GetCertificateChain(CertificateValue);
                PdfSignatureAppearance appearance = stamper.SignatureAppearance;
                X509CertificateParser cp = new X509CertificateParser();
                appearance.Certificate = cp.ReadCertificate(CertificateValue);
                appearance.SetVisibleSignature(new Rectangle(llx, lly, urx, ury), NumPage, FieldName);
                byte[] hash = this.CreateHash(appearance, chain);
                byte[] exSignature = this.MobilePKIHash(hash);
                this.AddSignature(appearance, exSignature);
            }   
            catch(Exception e)
            {
                File.AppendAllText(Directory.GetCurrentDirectory() + "/Log/Log.txt", "Ngày " + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss +0700") + ": Thực hiện Ký số thất bại! Lỗi --> " + e.ToString() + Environment.NewLine);
            }
        }

This is the error message dialog

  • 1
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – PajLe Mar 19 '22 at 12:10
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Mar 20 '22 at 07:59
  • Please show the stack trace of the error. – mkl Mar 21 '22 at 06:07

0 Answers0