This does not work for what I need as it only seems to encrypt and decrypt $filen and not the contents of the file. Perhaps the error has to do with the way I am writing the multi-line file out. I have tried using BINMODE however the output file is unreadable. Here is what my code does: I read a file and construct parameter name and parameter value pairs. I send these arrays to the code listed below for encryption. I then have a second Perl script which reads the encrypted file and decrypts it back to readable text. What I have tried: No BINMODE and I get the SALT error. Use BINMODE when outputting the encrypted file, use BINMODE when I read in the encrypted file. The result is the SALT error again. Use BINMODE when outputting the encrypted file, use BINMODE on both the input and output files when decrypting and the result is an output file in binary not text. Perhaps I am not understanding what you are trying to convey? Below is the code for encrypting:

use Crypt::CBC; my $cipher = Crypt::CBC->new( -key => 'fjeislqp12345678', -cipher => 'Blowfish'); # get input arrays my($name, $value) = @_; # open output files my($latest_file,$all_file, $latest_all_file); my($param_name, $param_value,$file_time,$lineout); my($cipher_text); $file_time = get_time_for_file(); $latest_file = "C:\\hc\\logs\\SC\\TO\\Bode_" . $utid . "_latest_" +. $file_time . ".txt"; open(LATEST, ">>",$latest_file) or die "Can't open $latest_file $! +\n"; binmode LATEST, ":encoding(UTF-8)"; # $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->encrypt($lineout); } print LATEST $cipher->finish(); close(LATEST);

Below is the code to decrypt:

#!C:\strawberry\perl\bin\perl # BEGIN { eval { require Crypt::Blowfish; }; } 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 = $ARGV[0]; $outf = "test.txt"; open(INFILE,$filen) or die "Can't open $filen for reading $!\n"; binmode INFILE, ":encoding(UTF-8)"; open(OUTFILE, ">>", $outf) or die "Can't open $outf to write: $!\n +"; # binmode OUTFILE, ":encoding(UTF-8)"; $cipher->start('decrypting'); # print OUTFILE $cipher->decrypt($_) while(<INFILE>); while (<INFILE>) { $line = $_; print OUTFILE $cipher->decrypt($line); } # print OUTFILE $cipher->finish(); $cipher->finish(); close(INFILE); close(OUTFILE);

In reply to Re^2: Cypto CBC and Blowfish by Will C
in thread 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.