crashev has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl
use Crypt::CBC;
$cipher = Crypt::CBC->new( -key => 'my secret key',
-cipher => 'Blowfish',
-header => 'none',
-iv => 'dupajasi'
);
$cipher->start('encrypting');
$sourcefile="fs9419105v001s.zip";
open(OUTF, ">$sourcefile.perl.crypt") || die;
open(F,"fs9419105v001s.zip");
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(OUTF, ">$sourcefile.perl.decrypt") || die;
open(F,"fs9419105v001s.zip.perl.crypt");
while (read(F,$buffer,1024)) {
print OUTF $cipher2->decrypt($buffer);
}
print OUTF $cipher2->finish;
close(OUTF);
OR
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use POSIX;
use File::Basename;
use Crypt::CBC;
use Digest::MD5 qw(md5 md5_hex);
# a) dencrypt
my $key="ed8677a0fc735e9bf1d7bca3310bb82854b5217589f2e00dd3bab399be9707a7";
my $sourcefile="fs9419105v001s.zip";
my $cipher = Crypt::CBC->new( {'key' => substr($key,0,32),
'cipher'=> 'Rijndael',
'blocksize' => 16,
'iv' => substr($key,32,16),
'regenerate_key' => 0,
'padding' => 'standard',
'prepend_iv' => 0,
'header' => 'none',
});
open (INF1, "< ".$sourcefile) || die;
open (OUTF1, "> ".$sourcefile.".perl.encrypt") || die;
$file_size = -s $sourcefile;
print "Sourcefile: $sourcefile $file_size \n";
print "block size: ".$cipher->blocksize()."\n";
print "? Encrypting ... \n";
while (my $size = read(INF1,my $buf, 8192 ) ) {
$count += $size;
$buf2 = $cipher->encrypt($buf);
print OUTF1 $buf2;
}
print OUTF1 $cipher->finish();
close(INF1);
close(OUTF1);
# a) decrypt
my $sourcefile="fs9419105v001s.zip.perl.encrypt";
open (INF1, "< ".$sourcefile) || die;
open (OUTF1, "> ".$sourcefile.".decrypt") || die;
$file_size = -s $sourcefile;
print "Sourcefile: $sourcefile $file_size \n";
print "block size: ".$cipher->blocksize()."\n";
print "? Decrypting ... \n";
while (my $size = read(INF1,my $buf, 8192 ) ) {
$count += $size;
$buf2 = $cipher->decrypt($buf);
print OUTF1 $buf2;
}
print OUTF1 $cipher->finish();
close(INF1);
close(OUTF1);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Aes or blowfish file encryption/decryption ?
by moritz (Cardinal) on Dec 02, 2010 at 15:03 UTC | |
by ikegami (Patriarch) on Dec 02, 2010 at 20:18 UTC | |
|
Re: Aes or blowfish file encryption/decryption ?
by locked_user sundialsvc4 (Abbot) on Dec 02, 2010 at 18:15 UTC | |
|
Re: Aes or blowfish file encryption/decryption ?
by ikegami (Patriarch) on Dec 02, 2010 at 20:30 UTC |