Pumeleon has asked for the wisdom of the Perl Monks concerning the following question:

Okay, I need some encryption on a program. I'm using Crypt::CBC with the Blowfish algorithm, but no matter what I do, it says that the data must be eight bytes long. I thought CBC handled that for you... This JUST is the important part of my code
my $Cipher = Crypt::CBC->new( {'key' => "My secret key. + Shush.", 'cipher' => 'Blowfish', 'padding' => 'null', 'iv' => '{3fd#t4^$#', 'regenerate_key' => 0, 'prepend_iv' => 0 }); $Cipher->start('e'); my $Shout = $dbh->quote($Cipher->crypt($q->param('Message'))); $cipher->finish();
Do I have to manually pad everything and chop it up into pieces of eight?

Replies are listed 'Best First'.
Re: CBC being a pain
by Thelonius (Priest) on Jan 23, 2005 at 00:25 UTC
    In the last line, the "c" in "$cipher" is lower case. Do you have another variable named "$cipher"?

    You should be aware that finish() may return characters that are part of the cryptext, so you need to append them. If you are just encrypting one small block, it's more convenient to call encrypt() instead of start(), crypt(), finish().

      I still have problems after changing it to encrypt(); which I had done previously to making it start() crypt() and end(). I still get the same error. Is there something in the order in which the my $Shout line that would cause this?
      my $Cipher = Crypt::CBC->new( {'key' => "Still secret. +Quiet, you.", 'cipher' => 'Blowfish', 'iv' => '{3fd#t4^$#', 'padding' => 'null', 'regenerate_key' => 0, 'prepend_iv' => 0 }); my $Shout = $dbh->quote($Cipher->encrypt($q->param('Message')));
      And yes, unfortunately, I miss caps all the time. ;_;
        >>And yes, unfortunately, I miss caps all the time. ;_;

        I feel obligated to make some reference to strict here...

        If you aren't already using strict, maybe try that and see if another typo becomes obvious.