#!/usr/bin/perl -w use Crypt::CBC; use MIME::Base64; use strict; my $plainin = "Now is the time for all good time for all good men to come to the aid of their party. The quick brown fox jumped over the lazy dog's back.\n"; my $cipher = Crypt::CBC->new( {'key' => 'Richard', 'cipher' => 'Blowfish', }); my $cryptext = $cipher->encrypt($plainin); # if you need to save the cryptext as ASCII, use something # like uuencoding: my $cipher_uuenc = pack("u", $cryptext); # or Base64 encoding (not built in to Perl, may need to install module) # (Use one or the other, not both. I just show both for pedagogical # purposes). my $cipher_base64 = encode_base64($cryptext); print "cipher_uuenc = $cipher_uuenc\n"; print "cipher_base64 = $cipher_base64\n"; my $cryptext2 = unpack("u", $cipher_uuenc); my $cryptext3 = decode_base64($cipher_base64); if ($cryptext2 eq $cryptext3) { print "Hey, they had better be equal!\n"; } else { print "Something is really screwed up!\n"; } my $cipherx = Crypt::CBC->new( {'key' => 'Richard', 'cipher' => 'Blowfish', }); my $plainout = $cipherx->decrypt($cryptext2); print "plainout =\n$plainout";