title: How to verify a custom formatted digital signature with iText?
body: <p>I am now writting a pdf viewer with whom I can put a custom formatted signature (using a Chinese SM2 encryption algorithm，that why I can't use the standard verify method,and that's why I must write my own pdf viewer)into a pdf and check it.The signing part,I calculate the hash,and then I sign the hash with a usbkey,and finally I put the signature into the pdf.
  But the checking part,I can't find any help and I don't know how can I go.I need to find a way to get the origin byte range and calculate the hash and then read the signature from the signature form field.And compare the hash with the old one to find out if the file is changed.Could anyone give me some sample code ?</p>
  
  <p>Here is some java code I found and rewrite it to c#,which I think may do some help,though some methods don't actully exist.</p>
  
  <pre><code>  PdfReader pdfReader = new PdfReader("D:\\Hello_world.pdf");
    PdfDocument pdfDocument = new PdfDocument(pdfReader);
    {
         SignatureUtil signatureUtil = new SignatureUtil(pdfDocument);
         foreach (String name in signatureUtil.GetSignatureNames())
          {
  
              PdfSignature signature = signatureUtil.getSignature(name);
              PdfArray b = signature.GetByteRange();
              RandomAccessFileOrArray rf = pdfReader.GetSafeFile();
              Stream rg = new RASInputStream(new RandomAccessSourceFactory().CreateRanged(rf.CreateSourceView(), SignatureUtil.AsLongArray(b)));
              Stream result = TARGET_STREAM_FOR_name_BYTES;
              {
                   byte[] buf = new byte[8192];
                   int rd;
                   while ((rd = rg.Read(buf, 0, buf.Length)) &gt; 0)
                   {
                        result.Write(buf, 0, rd);
                    }
               }
  
            }
      }
  </code></pre>