title: how to password protect the digitally signed pdf using iTextSharp?
body: <p>I m creating and signing pdf using c#,itextsharp.Now i m using this code for password protection and digital sign.First i am protecting with password.Than i am signing.</p>
  
  <p>the transmitted pdf is not asking password while opening?
  Can someone tellme why is this happening?</p>
  
  <p>Thanks..</p>
  
  <pre><code>string passprotectedfile = filename;
  
  using (Stream input = new FileStream(signedfile, FileMode.Open, FileAccess.Read,
                                       FileShare.Read))
  {
      using (Stream output = new FileStream(passprotectedfile, FileMode.Create, 
                                            FileAccess.Write, FileShare.None))
      {
          PdfReader reader = new PdfReader(input);
          PdfEncryptor.Encrypt(reader, output, true, regno.ToString(), "",
                               PdfWriter.ALLOW_SCREENREADERS);
      }
  }
  </code></pre>
  
  <p>Code i am using for digitally sign.</p>
  
  <pre><code>        PdfReader reader = new PdfReader(filename,pass);
          Stream output = new FileStream(signedfile, FileMode.Create, FileAccess.Write, FileShare.None);
          PdfStamper stamper = PdfStamper.CreateSignature(reader, output, '\0');
  
          Rectangle rect = new Rectangle(455, 105, 555, 170);
          PdfSignatureAppearance appearance = stamper.SignatureAppearance;
          appearance.SetVisibleSignature(rect, 1, "sign");
          PdfSignature dic = new PdfSignature(PdfName.ADOBE_PPKLITE, new PdfName("adobe.pkcs7.detached"));
          PrivateKeySignature pks = new PrivateKeySignature(pk, "SHA-256");
          MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, true);
          return filename;
  </code></pre>
  
  <p>then i am transmitting.</p>
  
  <pre><code>            Response.ContentType = "application/pdf";
              Response.AddHeader("content-disposition", "attachment;filename=tes2.pdf");
              Response.TransmitFile(signedfile);
              Response.Flush();
  
              File.Delete(signedfile);
              File.Delete(newfile);
              File.Delete(passprotectedfile);
  </code></pre>