title: Encrypt/decrypt binary file in Perl using blowfish or AES?
body: <p>I'm trying to encrypt and then decrypt a binary file in Perl without success, the decrypted file always differs from the original. I tried both Blowfish and AES (Rijandael), here is a short example:</p>
  
  <pre><code>#!/usr/bin/perl
  use Crypt::CBC;
  use autodie;
  
  my $cipher = Crypt::CBC-&gt;new(
      -key    =&gt; 'my secret key',
      -cipher =&gt; 'Blowfish',
      -header =&gt; 'none',
      -iv     =&gt; 'dupajasi'
  );
  $cipher-&gt;start('encrypting');
  my $sourcefile = "fs9419105v001s.zip";
  
  {
      open(my $OUTF, '&gt;', "$sourcefile.perl.crypt");
      open(my $F, '&lt;', $sourcefile);
      print "[?] Encrypting ... \n";
      while (read($F, $buffer, 1024)) {
          print $OUTF $cipher-&gt;crypt($buffer);
      }
      print {$OUTF} $cipher-&gt;finish;
      close($OUTF);
  }
  
  print "[?] Decrypting.,..... \n";
  $cipher2 = Crypt::CBC-&gt;new(
      -key    =&gt; 'my secret key',
      -cipher =&gt; 'Blowfish',
      -header =&gt; 'none',
      -iv     =&gt; 'dupajasi'
  );
  
  {
      open(my $OUTF, '&gt;', "$sourcefile.perl.decrypt");
      open(my $F, '&lt;', "$sourcefile.perl.crypt");
      while (read($F, $buffer, 1024)) {
          print {$OUTF} $cipher2-&gt;decrypt($buffer);
      }
      print {$OUTF} $cipher2-&gt;finish;
      close($OUTF);
  }
  </code></pre>
  
  <p>Can someone help me find out what is wrong?</p>