Hi. I am having problems using CBC and Blowfish. I have extensively searched the internet, including PerlMonks, and I cannot figure out what I am doing wrong. Below is the code I am using to encrypt:
use Crypt::CBC; my $cipher = Crypt::CBC->new( -key => 'fjeislqp12345678', -cipher => 'Blowfish'); .. various parameter and file declarations.. $cipher->start('encrypting'); for (my $i=0; $i < @$name; $i++) { $param_name = $name->[$i]; $param_value = $value->[$i]; $lineout = $param_name . "," . $param_value . "," . $filedate +. "," . $utid . "\n"; print LATEST $cipher->crypt($lineout); print ALLFILE $cipher->crypt($lineout); print LAFILE $cipher->crypt($lineout); } print LATEST $cipher->finish(); print ALLFILE $cipher->finish(); print LAFILE $cipher->finish();
All of the above seems to be working OK. However when I tried to decrypt I get the, now infamous, error message: Ciphertext does not begin with a valid header for 'salt' header mode. Below is the code I wrote for decrypting:
I would very much appreciate any assistance with this.#!C:\strawberry\perl\bin\perl # use Crypt::CBC; # my ($line, $outf, $filen); my $cipher = Crypt::CBC->new( -key => 'fjeislqp12345678', -cipher => 'Blowfish'); # get filename if($#ARGV == -1) { print STDERR "$runtime::No data directory specified on the com +mand line\n"; close(STDERR); exit; } $filen = $ARGV[0]; # $outf = "test.txt"; open(OUTFILE, ">>", $outf) or die "Can't open $outf to write: $!\n +"; open(INFILE,$filen) or die "Can't open $filen for reading $!\n"; $cipher->start('decrypting'); print OUTFILE $cipher->crypt($_) while(<INFILE>); # while (<INFILE>) { # $line = $_; # print OUTFILE $cipher->crypt($line); # } print OUTFILE $cipher->finish(); close(INFILE); close(OUTFILE);
In reply to Cypto CBC and Blowfish by Will C
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |