Security System iTextSharp PDF
<p>I am currently undertaking a process of taking a predetermined route the contents of folders in PDF and then change the properties of document security.</p>

<p>I am having problems with the security system, as I rebuilds the protected files (OwnerPassword)</p>

<p><a href="http://i.stack.imgur.com/MORK9.jpg" rel="nofollow">Img1</a>
<a href="http://i.stack.imgur.com/E5ppC.jpg" rel="nofollow">Img2</a></p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code> string[] files = Directory.GetFiles(fullPath, "*.pdf*", SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    fullPath = file.ToString();
                    positionLastSlash = fullPath.LastIndexOf("\\");
                    fullPath = fullPath.Substring(0, positionLastSlash + 1);
                    positionLastSlash2 = folderName.LastIndexOf("\\");
                    folderName = fullPath.Substring(positionLastSlash2 + 1);


                    PdfReader.unethicalreading = true;
                    //string password = "123";
                    //PdfReader reader = new PdfReader(file, PdfWriter.GetISOBytes(password));
                    PdfReader reader = new PdfReader(file);



                    if (file != null &amp;&amp; file.Contains(".pdf"))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            using (PdfStamper stamper = new PdfStamper(reader, ms))
                            {
                                // Aqui se pueden agregar propiedades de MetaData al documento                              
                            }
                            reader.Close();
                            
                            using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.ReadWrite))
                            {
                                
                                PdfEncryptor.Encrypt(
                                  new PdfReader(ms.ToArray()),
                                  fs,
                                  null,
                                  null,
                                  
                                        PdfWriter.ALLOW_PRINTING
                                      | PdfWriter.ALLOW_COPY
                                      | PdfWriter.ALLOW_MODIFY_CONTENTS
                                      | PdfWriter.ALLOW_ASSEMBLY
                                      | PdfWriter.ALLOW_DEGRADED_PRINTING
                                      | PdfWriter.ALLOW_FILL_IN
                                      | PdfWriter.ALLOW_MODIFY_ANNOTATIONS
                                      | PdfWriter.ALLOW_ASSEMBLY
                                      | PdfWriter.ALLOW_SCREENREADERS
                                      | PdfWriter.DO_NOT_ENCRYPT_METADATA
                                     
                                      ,
                                      true
                                );
                            }</code></pre>
</div>
</div>
</p>