view release on metacpan or search on metacpan
Revision history for Perl extension Filter::CBC.
0.0.1 Sat Nov 3 02:25:31 2001
- original version
0.0.2 Sun Nov 4 02:00:00 2001
- Added internal text converting
- Added some POD
0.03 Sun Nov 4 21:00:00 2001
- Cleaned up Package to improve CPANability
- Added some CBC Cipher examples
- Cleaned up and updated POD
0.04 Thu Nov 8 17:00:00 2001
- Added autoencryption feature (BIG CHANGE)
- Added cbc2code script
0.05 Fri Nov 9 23:00:00 2001
- Added default keyphrases & default encryption routines
- Cleaned up Package to improve CPANability
- Moved autofiltering to import block
0.08 Fri Dec 14 20:40:00 2001
- Removed horrible bug that screwed up on newlines
0.09 Thu Feb 14 21:00:00 2002
- Fixed \x bug again
- Fixed NULL example
0.10 Tue Sep 18 17:30:00 2007
- Fixed Salt bug for newer versions of Crypt::CBC
Changes
Makefile.PL
MANIFEST
README
t/Filter-CBC.t
lib/Filter/CBC.pm
examples/cbc2code.pl
examples/autofilter.pl
examples/blowfish.pl
examples/defaults.pl
examples/des_ede3.pl
examples/des.pl
examples/gost.pl
examples/idea.pl
examples/null.pl
examples/rc6.pl
# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
name: Filter-CBC
version: 0.10
version_from: lib/Filter/CBC.pm
installdirs: site
requires:
Crypt::CBC: 1.25
Crypt::Rijndael: 0.04
Filter::Util::Call: 1.05
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
Makefile.PL view on Meta::CPAN
use 5.008006;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Filter::CBC',
VERSION_FROM => 'lib/Filter/CBC.pm', # finds $VERSION
'PREREQ_PM' => {
'Filter::Util::Call' => '1.05',
'Crypt::CBC' => '1.25',
'Crypt::Rijndael' => '0.04',
},
($] >= 5.005 ? ## Add these new keywords supported since 5.005
(ABSTRACT_FROM => 'lib/Filter/CBC.pm', # retrieve abstract from module
AUTHOR => 'Hendrik Van Belleghem <hendrik@apple.com>') : ()),
);
README for Filter::CBC 0.10.
WHATIS
Filter::CBC is a Perl Source Filter that uses CBC (Cipher Block Chaining) to
encrypt/decrypt your sourcecode during runtime.
It uses the Filter module by Paul Marquess and Crypt::CBC by Lincoln Stein.
INSTALLING
Filter::CBC can be installed easily by using the CPAN module.
perl -MCPAN -e"install Filter::CBC"
or manually by untarring the archive and running the following commands.
perl Makefile.PM
make
make test
make install
TESTING
This module has been tested on Linux 2.4.x (x86) with Perl 5.6.1
EXAMPLES & SCRIPTS
Examples are included for all the CBC compatible encryption routines.
The code2cbc.pl script can encrypt your code by asking a number of simple
questions. The autoencryption feature does the same thing, without the
questions. code2cbc.pl can be found in the obsolete directory.
The cbc2code.pl script can decrypt encrypted scripts.
AUTOFILTER
Filter::CBC can now encrypt your source code on the fly (similar to
Acme::Bleach). Just add
use Filter::CBC 'Rijndael','my secret key';
above the chunk you want to encrypt et voila.
Change the use statement according to your requirements and run it.
Filter::CBC will now encrypt the source and exit. Your code will not
be executed at that time. PLEASE backup your code before running it.
PRETTY PLEASE.
REQUIREMENTS
Filter::CBC requires at least
Filter - http://search.cpan.org/search?dist=Filter
Crypt::CBC - http://search.cpan.org/search?dist=Crypt-CBC
Crypt::Rijndael - http://search.cpan.org/search?dist=Crypt-Rijndael
Also any Block Cipher routine you might want to use.
Among those compatible with CBC are :
Crypt::Rijndael - http://search.cpan.org/search?dist=Crypt-Rijndael
Crypt::DES - http://search.cpan.org/search?dist=Crypt-DES
Crypt::IDEA - http://search.cpan.org/search?dist=Crypt-IDEA
Crypt::Blowfish - http://search.cpan.org/search?dist=Crypt-Blowfish
Crypt::GOST - http://search.cpan.org/search?dist=Crypt-GOST
on how to handle parameters with use.
Paul Marquess for writing Filter and pointing out that Filter does what it should and not what I expect it to.
A bunch of monks at Perlmonks for giving some excellent and well appreciated feedback on
detecting code. Thank you Blakem, Petral, Chipmunk, Tilly, Jepri and Zaxo.
AUTHOR
Filter::CBC was written by Hendrik Van Belleghem. Suggestions & Questions
are welcome at hendrik dot vanbelleghem - at - gmail - dot - com.
Yes, I love fanmail! No, I don't like spam.
examples/autofilter.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
use Filter::CBC "Rijndael","my secret key";
# This file will be encrypted and overwritten.
# Make backups, damnit!
# Autofilter example
print "Don't try this at home, kids !";
examples/cbc2code.pl view on Meta::CPAN
#!/usr/bin/perl
# CBC2CODE
# This small script will decrypt your Filter::CBC'ed code back to your
# plain code by reading the algorithm and the key.
# This script is part of Filter::CBC. Same license rules apply.
use strict;
use Crypt::CBC;
my $blank = "This space is left blank intentionally";
my %Algorithms =
("RIJNDAEL"=>"Rijndael",
"DES"=>"DES",
"IDEA"=>"IDEA",
"BLOWFISH"=>"Blowfish",
"GOST"=>"GOST",
"DES_EDE3"=>"DES_EDE3",
"TWOFISH"=>"Twofish",
examples/cbc2code.pl view on Meta::CPAN
die "File $file does not exist !" unless -e $file;
die "File $file is a directory !" unless !-d $file;
open(F,"<$file") || die $!;
my ($past_use,$key,$algorithm,$found);
$found = 0;
my @code = ();
while(<F>)
{ if (/^\# $blank/) { $found++; }
if (!$past_use)
{ ($algorithm,$key) = /use Filter\:\:CBC\s*[\'\"](\w*)[\'\"]\s*\,\s*[\'\"]([^\'\"]*)[\'\"].*?/; }
if (defined $algorithm && defined $key && !$past_use) { $past_use++; push(@code ,$_); next;}
if ($past_use && defined $key && defined $algorithm && $_ ne $/ && $found)
{ my (@foo) = <F>;
unshift (@foo,$_);
my $code = join("",@foo);
$algorithm ||= "Rijndael";
$algorithm = $Algorithms{uc $algorithm} || $algorithm;
$key ||= $blank;
my $cipher = new Crypt::CBC($key,$algorithm);
$code = $cipher->decrypt($code);
open(OUTFILE,">$file.out") || die $!;
print OUTFILE @code,$code;
close(OUTFILE);
}
else { push(@code,$_); }
}
close(F);
}
examples/defaults.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
use Filter::CBC "","";
# This file will be encrypted and overwritten.
# Make backups, damnit!
# Autofilter example
# Defaults will be used
# Rijndael is default encryption algorithm
# Default keyphrase is : This space is left blank intentionally
print "Don't try this at home, kids !";
examples/des.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
# This space is left blank intentionally
use Filter::CBC "DES","my secret key";
RandomIVîëÚóË¿¿Æa¸å©½úÇTK(ü0Ã̸<4oòÆÑÙ˵íñ)¡
¢NoiÁò_ßT"ñqÔyÞ.¿ÆÊhOÖ¢Tóiͳ©EJ!/¸2Ì£¡|Göëx%Í|z/+«=?ùõMs¿v/;ITVj?ß½½q¿´
examples/gost.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
# This space is left blank intentionally
use Filter::CBC "GOST","my secret key";
RandomIV¼Ã~ÒÌÔ|o&þ
ù%c,ôK5õÿbXäX`ZQiSðV%æUMgß^¦e#/:¯ö§êÚÃFQÅ$haöÔIf#MÐkê®ÇLTIÚå¾òxS¼³×[Òt½ÿcòÔ£y¾
9xíRí
examples/tea.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
# This space is left blank intentionally
use Filter::CBC "TEA","my secret key";
RandomIVüÌøÐ"ÜÄ¢åOÕSA0PYYÖçzâè
`7kê»Tý;¯ì!O
eoÿ 4q/ûpÅ¥<ÝEÍгéÄ®ù«ÀB'[VÍÑ0ØØ=Æ8ò|Ùr%ÔPÕB^ÊÊ·nrên´fÜâÅ&»ÃLe"n`y,/^ýì@ZíîÏÁ¡
examples/twofish.pl view on Meta::CPAN
#!/usr/bin/perl
# Please don't encrypt me!
# This space is left blank intentionally
use Filter::CBC "Twofish","my secret key";
RandomIVga#3Äðtè%_fUãÖ
ì-£+Úò·>tÞc<0PMÏéoÐÙÄ1ѵd£ .¼ö1AÎ;zD¿¬è`-¢îÏ ÷ëùY
í°c÷a¿û_Ã#4¸¹!àÌClªûøN<ÍUx]$·%¤°õgY/NAÆò[híAn`RîÒ
lib/Filter/CBC.pm view on Meta::CPAN
package Filter::CBC;
use strict;
use vars qw($VERSION $cipher %Ciphers);
use Filter::Util::Call ;
use Crypt::CBC;
my %Ciphers =
("BLOWFISH"=>"Blowfish",
"DES"=>"DES",
"DES_EDE3"=>"DES_EDE3",
"GOST"=>"GOST",
"IDEA"=>"IDEA",
"NULL"=>"NULL",
"RC6"=>"RC6",
"RIJNDAEL"=>"Rijndael",
lib/Filter/CBC.pm view on Meta::CPAN
$VERSION = '0.10';
my $blank = "This space is left blank intentionally";
sub import {
my ($type) = shift @_;
my $algorithm = shift || "Rijndael";
$algorithm = $Ciphers{uc $algorithm} || $algorithm;
my $key = shift || $blank;
my ($ref) = [];
$cipher = Crypt::CBC->new(-key => $key,-cipher => $algorithm);
if (defined $algorithm && defined $key)
{ open(F,"<$0") || die $!;
flock(F,2); seek(F,0,0);
my @CODE = ();
my $past_use;
while(<F>)
{ if (/^\# $blank/ && !$past_use) { close(F); last; }
if (/use Filter\:\:CBC/) { push(@CODE,$_); $past_use++; next; }
if (!$past_use) { push(@CODE,$_); }
else
{ my $code = $_; local $/ = undef; $code .= <F>;
splice(@CODE,-2,0,"# $blank");
$code = $cipher->encrypt($code);
open(OUTFILE,">$0.bak") || die $!;
binmode(OUTFILE);
print OUTFILE @CODE,$code;
close(OUTFILE);
close(F);
lib/Filter/CBC.pm view on Meta::CPAN
}
$status ;
}
1;
__END__
=pod
=head1 NAME
Filter::CBC - Source filter for Cipher Block Chaining
=head1 SYNOPSIS
# Please don't encrypt me!
use Filter::CBC "Rijndael","my secret key";
# This file will be encrypted and overwritten.
# Make backups, damnit!
# Autofilter example
print "Don't try this at home, kids !";
-or-
# Please don't encrypt me!
use Filter::CBC "","";
# This file will be encrypted and overwritten.
# Make backups, damnit!
# Autofilter example
# Defaults will be used
# Rijndael is default encryption algorithm
# Default keyphrase is : This space is left blank intentionally
print "Don't try this at home, kids !";
-or-
BEGIN { use LWP::Simple; my $key = get("http://www.somesite.com/key.txt"); }
use Filter::CBC "Rijndael",$key;
secretstuff();
=head1 DESCRIPTION
Filter::CBC is a Source filter that uses Cipher Block Chaining (CBC) to
encrypt your code. The tricky part is that most CBC Algorithms have binary
output. The textmode bypasses this obstacle, by converting the data to less scary data.
=head1 DOWNSIDES
=over 3
=item *
Source filters are slow. VERY Slow. Filter::CBC is not an exception.
Well uhm kinda. Filter::CBC is even slower. Be warned, be VERY VERY warned.
=back
=over 3
=item *
You're source file is overwrittten when you're using the autoefilter feature.
=back
=head1 PARAMETERS
The two parameters that can be passed along are :
=over 2
=item CBC Handler
This parameter indicates what CBC encryption routine to use. Possible values are described in the next section.
=item Keyphrase
This parameter is the keyphrase for the encryption routine described as previous parameter.
=back
=head1 INTERNAL CBC HANDLERS
The following parameters can be passed as part of the CBC encryption routine
=over 2
=item Rijndael
This is the AES (Advanced Encryption Scheme) routine. You need
Crypt::Rijndael for this.
=item DES
lib/Filter/CBC.pm view on Meta::CPAN
This is the RC6 routine. You need Crypt::RC6 for this.
=item Serpent
This is the Serpent routine. You need Crypt::Serpent for this.
(Untested)
=back
But any CBC Compatible routine will work.
=head1 TEXT HANDLERS
As Paul Marquess noted, Filter has no problems with binary data. The text handlers
are totally unnecesary. I therefor removed them. You can still use hex encoding by using
the Filter::Hex module provided in the obsolete directory. If you have code that used the
older version of Filter::CBC, I recommend stacking the HEX filter. Edit the use statement as follows :
use Filter::Hex; use Filter::CBC "Rijndael","my secret key";
=head1 AUTOFILTERING
Since Filter::CBC 0.04, using code2cbc isn't required anymore. Filter::CBC can encrypt your code
on the fly if it's not yet encrypted. Be warned that your source file is overwritten. You can use
cbc2code.pl to decrypt your encrypted code. BACKUP!
use Filter::CBC "Rijndael","my secret key";
# This file will be encrypted and overwritten.
# Make backups, damnit!
# Autofilter example
print "Don't try this at home, kids !";
This code will be encrypted the first time you run it. Everything before the 'use Filter::CBC' line is kept
intact. Filter::CBC sets a 'marker' so that double encryption doesn't occur.
If you see a comment stating 'This space is left blank intentionally', ignore it.
=head1 DEFAULTS
=over 3
=item Encryption routine
Filter::CBC will use Rijndael when no encryption algorithm is defined.
=back
=over 3
=item Keyphrase
Filter::CBC will use the following line when no keyphrase is defined :
=back
I<This space is left blank intentionally>
=head1 REQUIREMENTS
Filter::CBC requires the following modules (depending on your needs)
=over 3
=item Filter::Util::Call
=item Crypt::CBC
=item Crypt::Rijndael
=item Crypt::DES
=item Crypt::IDEA
=item Crypt::Blowfish
=item Crypt::GOST
lib/Filter/CBC.pm view on Meta::CPAN
A bit less then first release but still plenty.
=head1 DISCLAIMER
This code is released under GPL (GNU Public License). More information can be
found on http://www.gnu.org/copyleft/gpl.html
=head1 VERSION
This is Filter::CBC 0.09
=head1 AUTHOR
Hendrik Van Belleghem (beatnik -at- quickndirty -dot- org)
=head1 SEE ALSO
GNU & GPL - http://www.gnu.org/copyleft/gpl.html
Filter::Util::Call - http://search.cpan.org/search?dist=Filter
Crypt::CBC - http://search.cpan.org/search?dist=Crypt-CBC
Crypt::Rijndael - http://search.cpan.org/search?dist=Crypt-Rijndael
Crypt::DES - http://search.cpan.org/search?dist=Crypt-DES
Crypt::IDEA - http://search.cpan.org/search?dist=Crypt-IDEA
Crypt::Blowfish - http://search.cpan.org/search?dist=Crypt-Blowfish
Crypt::GOST - http://search.cpan.org/search?dist=Crypt-GOST
t/Filter-CBC.t view on Meta::CPAN
#!/usr/bin/perl
use Test::More tests => 1;
#use Filter::CBC 'Rijndael','Filter::CBC test';
my $result = 1;
#print "1..1\n";
ok($result);