title: Problems encrypting a PDF file using PHP filters
body: <p>Hi I'm trying to write code that uploads a pdf file, then ftps it to a NAS box and then allows the user to view the document - i.e the reverse get the doc back via ftp from the nas.  Everything works great.  However I now need to encrypt the data on the NAs box.  I read about filters But I can't make it work  The only stuff I've seen is for text.  Where I'm up to now is:</p>
  
  <p>the sending code</p>
  
  <pre><code> $passphrase = 'My secret';
  
   /* Turn a human readable passphrase
    * into a reproducable iv/key pair
    */
   $iv = substr(md5('iv'.$passphrase, true), 0, 8);
   $key = substr(md5('pass1'.$passphrase, true) . 
                  md5('pass2'.$passphrase, true), 0, 24);
   $opts = array('iv'=&gt;$iv, 'key'=&gt;$key);
  
   $fp = fopen($file, 'wb');//$file is tne uploaded file
   stream_filter_append($fp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
   fwrite($fp, 'Secret secret secret data');// I know this bit is wrong!!
   fclose($fp);
  
   if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
         //echo "successfully uploaded $file\n";
  </code></pre>
  
  <p>So I changed it inlie with the comments</p>
  
  <pre><code> $passphrase = 'My secret';
  
   /* Turn a human readable passphrase
    * into a reproducable iv/key pair
    */
   $iv = substr(md5('iv'.$passphrase, true), 0, 8);
   $key = substr(md5('pass1'.$passphrase, true) . 
                  md5('pass2'.$passphrase, true), 0, 24);
   $opts = array('iv'=&gt;$iv, 'key'=&gt;$key);
  
   $fp = fopen($file, 'wb');
   $fplocal = fopen("templocal.PDF", 'wb');
  
   stream_filter_append($fplocal, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts);
   fwrite($fplocal, $fp);
   fclose($fplocal);
   fclose($fp);
  
  
        // try to upload $file
        if (ftp_put($conn_id, $remote_file, $fplocal,
  </code></pre>
  
  <p>but it doesn't work - am I doning something wrong?</p>