Encrypt/decrypt binary file in Perl using blowfish or AES? -
i'm trying encrypt , decrypt binary file in perl without success, decrypted file differs original. tried both blowfish , aes (rijandael), here short example:
#!/usr/bin/perl use crypt::cbc; use autodie; $cipher = crypt::cbc->new( -key => 'my secret key', -cipher => 'blowfish', -header => 'none', -iv => 'dupajasi' ); $cipher->start('encrypting'); $sourcefile = "fs9419105v001s.zip"; { open(my $outf, '>', "$sourcefile.perl.crypt"); open(my $f, '<', $sourcefile); print "[?] encrypting ... \n"; while (read($f, $buffer, 1024)) { print $outf $cipher->crypt($buffer); } print {$outf} $cipher->finish; close($outf); } print "[?] decrypting.,..... \n"; $cipher2 = crypt::cbc->new( -key => 'my secret key', -cipher => 'blowfish', -header => 'none', -iv => 'dupajasi' ); { open(my $outf, '>', "$sourcefile.perl.decrypt"); open(my $f, '<', "$sourcefile.perl.crypt"); while (read($f, $buffer, 1024)) { print {$outf} $cipher2->decrypt($buffer); } print {$outf} $cipher2->finish; close($outf); }
can me find out wrong?
i can confirm this. found hint: difference occurs @ 102410/40016 boundary.
> diff -u fs9419105v001s.zip.hex fs9419105v001s.zip.perl.decrypt.hex --- fs9419105v001s.zip.hex +++ fs9419105v001s.zip.perl.decrypt.hex @@ -62,7 +62,7 @@ 03d0 5d d9 f2 f6 43 bb 3d 9d 92 aa 89 ca 75 dc 0e 51 ]...c.=. ....u..q 03e0 55 b2 1a e8 65 d5 29 ac ca d9 a4 f8 1a cc 67 8b u...e.). ......g. 03f0 f9 1b 65 bc 19 bf 51 e6 9f de 28 ef db db ff ..e....q ...(.... -0400 85 38 78 09 a7 62 9f 9d 08 db fc cb 13 90 b9 84 .8x..b.. ........ +0400 c6 a0 8b 75 f4 17 6b 64 08 db fc cb 13 90 b9 84 ...u..kd ........ 0410 f4 a8 30 d2 1d 19 52 f7 8e 84 09 a8 59 f3 4e 1e ..0...r. ....y.n. 0420 3c 30 ca 6e 5b dc bb f3 48 fa 5d 3c b1 e0 64 07 <0.n[... h.]<..d. 0430 61 98 9e a1 57 9a 69 d6 35 a7 95 5b 0d d7 31 c4 a...w.i. 5..[..1.
this more comment answer, unfortunately comment box not suitable reply.
Comments
Post a Comment