LibWeb
view release on metacpan or search on metacpan
LibWeb/Crypt.pm view on Meta::CPAN
# Use standard library.
use strict;
use vars qw($VERSION @ISA);
#-#############################
# Use custom library.
# This class should not require LibWeb::Core.
# You have been warned!.
require Crypt::CBC;
require LibWeb::Class;
##require Crypt::Blowfish; Crypt::IDEA, or Crypt::DES;
#-#############################
# Version.
$VERSION = '0.02';
#-#############################
# Inheritance.
@ISA = qw(LibWeb::Class);
#-#############################
LibWeb/Crypt.pm view on Meta::CPAN
$Class = ref($class) || $class;
$self = $Class->SUPER::new(shift);
bless($self, $Class);
}
sub DESTROY {}
sub encrypt_cipher {
#
# Params: -data=>, -key=>, -algorithm=>, -format=>
# e.g. -algorithm => 'Crypt::Blowfish' / 'Crypt::DES' / 'Crypt::IDEA'
# e.g. -format => 'binary' / 'hex'.
# This makes use of Crypt::CBC module. Accept data of arbitrary length.
#
my ($self, $data, $key, $algorithm, $format, $cipher);
$self = shift;
($data, $key, $algorithm, $format) =
$self->rearrange(['DATA', ,'KEY', 'ALGORITHM', 'FORMAT'], @_);
# Makes perl taint mode happy. $1 is $cipherAlgorithm in disguise.
$algorithm =~ m:(.*):;
$cipher = new Crypt::CBC($key, $1);
return (uc($format) eq 'HEX') ?
$cipher->encrypt_hex($data) : $cipher->encrypt($data);
}
sub decrypt_cipher {
#
# Params: -cipher=>, -key=>, -algorithm=>, -format=>
# e.g. -algorithm => 'Crypt::Blowfish' / 'Crypt::DES' / 'Crypt::IDEA'
# e.g. -format => 'binary' / 'hex'.
# This makes use of Crypt::CBC module. Accept cipher generated by
# encrypt_cipher() of this module (LibWeb).
#
my ($self, $cipherText, $key, $algorithm, $format, $cipher);
$self = shift;
($cipherText, $key, $algorithm, $format) =
$self->rearrange(['CIPHER', 'KEY', 'ALGORITHM', 'FORMAT'], @_);
# Makes perl taint mode happy. $1 is $cipherAlgorithm in disguise.
LibWeb/Crypt.pm view on Meta::CPAN
=head1 REQUIRE
=over 2
=item *
Crypt::CBC
=item *
Crypt::Blowfish (recommended), Crypt::DES or Crypt::IDEA
=back
=head1 ISA
=over 2
=item *
LibWeb::Class
LibWeb/Crypt.pm view on Meta::CPAN
=head1 ABSTRACT
This class provides methods to
=over 2
=item *
encrypt data of arbitrary length into cipher (binary or hex) by using
the algorithm provided by Crypt::Blowfish, Crypt::DES or Crypt::IDEA,
and chained by using Crypt::CBC,
=item *
decrypt ciphers generated by this class,
=item *
encrypt plain text password by using the perl's crypt() routine with
randomly chosen salt.
LibWeb/Crypt.pm view on Meta::CPAN
C<-data> is the data to be encrypted as cipher,
=item *
C<-key> is the private key such the same key is needed to decrypt the
cipher (sorry, I do not have a rigorous definition for that right
now),
=item *
C<-algorithm> must be 'Crypt::Blowfish', 'Crypt::DES' or
'Crypt::IDEA',
=item *
C<-format> is the format of the cipher, which must be either 'binary'
or 'hex'.
=back
Post:
LibWeb/Crypt.pm view on Meta::CPAN
C<-cipher> is the cipher to be decrypted,
=item *
C<-key> is the private key such that it is the same key used to
encrypt the original data of C<-cipher> (sorry, I do not have a
rigorous definition for that right now),
=item *
C<-algorithm> must be 'Crypt::Blowfish', 'Crypt::DES' or 'Crypt::IDEA'
and it must match the algorithm used when preparing the cipher,
=item *
C<-format> is the format of the cipher, which must be either 'binary'
or 'hex'.
=back
Post:
LibWeb/Crypt.pm view on Meta::CPAN
=back
=head1 BUGS
=head1 SEE ALSO
L<Digest::HMAC>, L<Digest::SHA1>, L<Digest::MD5>, L<Crypt::CBC>,
L<Crypt::Blowfish>, L<Crypt::DES>, L<Crypt::IDEA>, L<LibWeb::Admin>,
L<LibWeb::Digest>, L<LibWeb::Session>.
=cut
LibWeb/Digest.pm view on Meta::CPAN
=item Lincoln Stein (lstein@cshl.org)
=back
=head1 BUGS
=head1 SEE ALSO
L<Digest::HMAC>, L<Digest::SHA1>, L<Digest::MD5>, L<Crypt::CBC>,
L<Crypt::Blowfish>, L<Crypt::DES>, L<Crypt::IDEA>, L<LibWeb::Admin>,
L<LibWeb::Crypt>, L<LibWeb::Session>.
=cut
http://search.cpan.org/search?dist=Digest-MD5
* Crypt::CBC
http://search.cpan.org/search?dist=Crypt-CBC
* Crypt::Blowfish (recommended)
http://search.cpan.org/search?dist=Crypt-Blowfish
or Crypt::DES
http://search.cpan.org/search?dist=Crypt-DES
or Crypt::IDEA
http://search.cpan.org/search?dist=Crypt-IDEA
* DBI
http://search.cpan.org/search?dist=DBI
eg/dot_lwrc view on Meta::CPAN
This key is appended to the data from which a digest is to be
generated. The purpose is to have different web site with LibWeb
installed to have different and less predictable behavior in several
aspects of the authentication cookie.
=item *
CIPHER_ALGORITHM
The cipher algorithm must be C<'Crypt::Blowfish'>, C<'Crypt::DES'> or
C<'Crypt::IDEA'> as of LibWeb-0.01.
=item *
DIGEST_ALGORITHM
The digest algorithm must be either C<'Digest::SHA1'> or
C<'Digest::MD5'> as of LibWeb-0.01.
=item *
eval "use Crypt::CBC";
if ($@) {
warn "Crypt::CBC module not installed.\n";
print "1..0\n";
exit;
}
my $cipher_algo;
eval "use Crypt::IDEA"; $cipher_algo = 'Crypt::IDEA' if !$@;
eval "use Crypt::DES"; $cipher_algo = 'Crypt::DES' if !$@;
eval "use Crypt::Blowfish"; $cipher_algo = 'Crypt::Blowfish' if !$@;
unless ( defined $cipher_algo ) {
warn "Crypt::Blowfish/Crypt::DES/Crypt::IDEA module not installed.\n";
print "1..0\n";
exit;
}
print "1..2\n";
# Set up a CGI environment
$ENV{REQUEST_METHOD} = 'GET';
$ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull';
$ENV{PATH_INFO} = '/somewhere/else';
# Test to see if dependencies have been installed.
eval "use Crypt::CBC";
if ($@) {
warn "Crypt::CBC module not installed.\n";
print "1..0\n";
exit;
}
my $cipher_algo;
eval "use Crypt::IDEA"; $cipher_algo = 'Crypt::IDEA' if !$@;
eval "use Crypt::DES"; $cipher_algo = 'Crypt::DES' if !$@;
eval "use Crypt::Blowfish"; $cipher_algo = 'Crypt::Blowfish' if !$@;
unless ( defined $cipher_algo ) {
warn "Crypt::Blowfish/Crypt::DES/Crypt::IDEA module not installed.\n";
print "1..0\n";
exit;
}
print "1..9\n";
# Set up a CGI environment
$ENV{REQUEST_METHOD} = 'GET';
$ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull';
$ENV{PATH_INFO} = '/somewhere/else';
# test_LibWeb_Crypt
eval "use LibWeb::Crypt";
test(1, !$@, "Could not load LibWeb::Crypt module. $@");
my $crypt;
eval { $crypt = LibWeb::Crypt->new(); };
test(2, !$@, "LibWeb::Crypt cannot be instantiated. $@");
test(3, $cipher_algo,
'Crypt::Blowfish or Crypt::DES or Crypt::IDEA not found.');
if ($crypt && $cipher_algo) {
my $is_encrypt_cipher_diff_data_ok;
eval { $is_encrypt_cipher_diff_data_ok = $crypt->encrypt_cipher(
-data => 'hello world',
-key => '1234abcd',
-algorithm => $cipher_algo,
-format => 'hex'
)
ne $crypt->encrypt_cipher(
t/Session.t view on Meta::CPAN
eval "use Crypt::CBC";
if ($@) {
warn "Crypt::CBC module not installed.\n";
print "1..0\n";
exit;
}
my $cipher_algo;
eval "use Crypt::IDEA"; $cipher_algo = 'Crypt::IDEA' if !$@;
eval "use Crypt::DES"; $cipher_algo = 'Crypt::DES' if !$@;
eval "use Crypt::Blowfish"; $cipher_algo = 'Crypt::Blowfish' if !$@;
unless ( defined $cipher_algo ) {
warn "Crypt::Blowfish/Crypt::DES/Crypt::IDEA module not installed.\n";
print "1..0\n";
exit;
}
print "1..2\n";
######################### End of black magic.
# Insert your test code below (better if it prints "ok 13"
# (correspondingly "not ok 13") depending on the success of chunk 13
( run in 0.289 second using v1.01-cache-2.11-cpan-9a3d99fc6dc )