Apache-CryptHash

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

3.01  Fri Jan  3 16:17:48 PST 2003
	documentation update

3.00  Sun Sep 22 16:15:16 PDT 2002
	change group name to Apache

2.07  Fri Sep 13 21:02:13 PDT 2002
	update documentation on "decode"

2.06  Thu Sep 12 20:46:30 PDT 2002
	change default password the the value
	returned by Sys::Hostname::hostname;

2.05  Wed Jan 24 21:17:47 PST 2001
	remove 'warnings' from t/basic.t for compatibility
	with older versions of perl

2.04  Tue Jan 2, 13:34:00 PST 2001
	my $secret replaced with $self->{CRYPT}
	error found where MAC used @keys instead of @vals
	did some other bug fixes

CryptHash.pm  view on Meta::CPAN

  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;
}

sub name {
  &_readNset(\shift->{NAME},@_);
}

CryptHash.pm  view on Meta::CPAN

=item C<md5_hex($)>

Return the md5 hash of input string.

=item C<md5_b64($)>

Return the md5 base 64 hash of input string.

=item C<checkMAC>

  $c = Apache::CryptHash->init('some password');
  $c->checkMAC(\%state, \@mac_keys)

Does a comparison of the MAC in the B<%state> vs the calculated value based
on B<@mac_keys> and returns a boolean result.

Don't forget to set the B<passcode> or the check will fail!

=back

=head1 SEE ALSO

t/basic.t  view on Meta::CPAN

$expected = 'nfNXVulg4TVVpCOvS7j7zg';
$md5val = $c->md5_b64($name);
if ( $expected ne $md5val ) {
  print "bad md5_b64=$md5val\nexpect b64v=$expected\nnot ";
} 
print "ok $testno\n";
++$testno;


$name = 'Harry';
$c = Apache::CryptHash->init('password2');;
$c->name($name);

$v = undef;
$v = $c->encode(\%x, \@k);
$dc = $v;		# decrypted string

$c = Apache::CryptHash->init;
$c->name($name);
$c->passcode('password2');
unless ($rv = $c->decode(\$dc, \%z, \@check)) {
  print 'failed decrypt', "\nnot ";
}
print "ok $testno\n";
++$testno;

unless ( $rv eq  $name ) {
  print "decode did not return '", $name, "'\nnot ";
}
print "ok $testno\n";



( run in 0.509 second using v1.01-cache-2.11-cpan-49f99fa48dc )