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:

#!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);
I would very much appreciate any assistance with this.

In reply to Cypto CBC and Blowfish by Will C

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.