Apache-CryptHash
view release on metacpan or search on metacpan
CryptHash.pm view on Meta::CPAN
BEGIN {
# use Apache;
use MIME::Base64;
use Crypt::CapnMidNite;
use vars qw($VERSION);
$VERSION = do { my @r = (q$Revision: 3.03 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
}
sub init() {
my ($proto, $crypt) = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{NAME} = 'Secret'; # default header name
$self->{CRYPT} = $crypt || do { # default password is hostname
require Sys::Hostname; # 'no, NO' turns encryption off
&Sys::Hostname::hostname;
};
bless ($self, $class);
return $self;
CryptHash.pm view on Meta::CPAN
$$var = $new if defined $new;
return $rv;
}
#####################################################
# md5_hex
#
# input: string
# returns: md5 hex hash of string
#
sub md5_hex($$) {
my ($self, $string) = @_;
return Crypt::CapnMidNite->new->md5_hex($string);
}
#####################################################
# md5_b64
#
# input: string
# returns: md5 base 64 of string
#
sub md5_b64($$) {
my ($self, $string) = @_;
return Crypt::CapnMidNite->new->md5_base64($string);
}
#####################################################
# encode
# create an encrypted cookie from data values passed in hash
# input: pointer to hash, # \%p
# (optional) pointer to keys # \@k
# (array) of values to include in MAC
# these must be invarient and will
# fail to decrypt otherwise
#
sub encode($$$) {
my ( $self, $state, $k ) = @_; # get my self
&_MAC($self, $state, $k, 'generate'); # add MAC to state
my $cipher = Crypt::CapnMidNite->new_md5_rc4($self->{CRYPT});
my %s = %$state;
foreach (keys %s) {
$s{$_} =~ s/:/%58/g;
}
my $cook = $self->{NAME};
if ( $self->{CRYPT} =~ /^no$/i ) {
$cook .= '.Debug:' . join ':', %s;
( run in 0.322 second using v1.01-cache-2.11-cpan-65fba6d93b7 )