jinyedge's note
{http://www.jinyedge.pe.kr}


Hi, this is jinyedge. I'm a software developer. I hope you can find some useful information in my homepage.


jinyedge at gmail.com
Since 2001.12.05

 

 
Subj Cont
 
Subj: Perl, Crypt with CBC, Blowfish, base64.
Mtime: 2009-09-30 19:54:27

#!/usr/bin/perl
use Crypt::CBC;
use MIME::Base64 qw/encode_base64 decode_base64/;

my $cbc_key = "This is a secret";

#------------------------------------------------------
sub cbc_enc{
    my $line = shift;

    my $cipher = new Crypt::CBC(-key => $cbc_key, -cipher => `Blowfish`);

    my $res = encode_base64($cipher->encrypt($line));
    chomp($res);

    return $res;
}

#------------------------------------------------------
sub cbc_dec{
    my $line = shift;

    $line = decode_base64($line);

    my $cipher = new Crypt::CBC(-key => $cbc_key, -cipher => `Blowfish`);
    return $cipher->decrypt($line);
}

#------------------------------------------------------
#main.

my $enc = cbc_enc("I need some encrypt method!");
chomp $enc;
my $dec = cbc_dec($enc);

print "$enc\n$dec\n";