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 |