From the Crypt::Blowfish manpage:

$plaintext and $ciphertext must be of "blocksize()" bytes. (hint: Blowfish is an 8 byte block cipher)
If you want to encrypt/decrypt text which is not exactly 8 bytes, you will need to read up on Crypt:CBC

Update: Here is something closer to working, but it still has a few problems:

#!/usr/bin/perl -w use strict; use diagnostics; use Crypt::CBC; my $key=pack("H16","0123456789ABCDEF"); my $cipher = Crypt::CBC->new({ cipher => 'Blowfish', key => $key, regenerate_key => 0, }); $cipher->start('encrypting'); print "Enter some text: "; my $text=<STDIN>; chomp($text); print $cipher->crypt($text); print $cipher->finish; print "\n";
The main problem I see is that it is sending a human prompt and encrypted text to stdout. The encrypted text will be in binary format and so could include high bit characters that mess up your ability to read your terminal output. It's also pretty useless to read.

You're going to want to send the encrypted text to some file or other process, in which case you'll want to change the prompt to go to stderr or the terminal.

Also, were you wanting to encrypt a single line of input? Multiple lines of input independently? Multiple lines of input as a single encrypted chunk?

Then again, perhaps you wisely just provided a small test case which shows your core problem instead of including your entire application which does something else entirely.

-- Eric Hammond


In reply to Re: Blowfish.pm by esh
in thread Blowfish.pm: "input must be * bytes long" by phax

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.