Apache-CryptHash
view release on metacpan or search on metacpan
my $dc = $v; # decrypted string
my $rv; # return value
$c = Apache::CryptHash->init;
$c->name($name);
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";
++$testno;
foreach (sort keys %x) {
unless ( $z{$_} eq $x{$_} ) {
print "items don't match $_\torig=$x{$_} dcrypt=$z{$_}\n";
++$failed;
}
}
print 'not ' if $failed;
print "ok $testno\n";
++$testno;
$bad{MAC} = $z{MAC}; # setup bad decode array
unless ( $c->checkMAC( \%z, \@check )) {
print "failed good MAC check\nnot ";
}
print "ok $testno\n";
++$testno;
if ( $c->checkMAC( \%bad, \@check )) {
my $zy = $c->checkMAC( \%bad, \@check );
print "passed?? bad MAC check\nnot ";
}
print "ok $testno\n";
++$testno;
my $expected = '9df35756e960e13555a423af4bb8fbce';
my $md5val = $c->md5_hex($name);
if ( $expected ne $md5val ) {
print "bad md5_hex=$md5val\nexpect hexv=$expected\nnot ";
}
print "ok $testno\n";
++$testno;
$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";
++$testno;
foreach (sort keys %x) {
unless ( $z{$_} eq $x{$_} ) {
print "items don't match $_\torig=$x{$_} dcrypt=$z{$_}\n";
++$failed;
}
}
print 'not ' if $failed;
print "ok $testno\n";
++$testno;
$expected = 'db05833c29e688b5ab54d5e8608a72ec';
$md5val = $c->md5_hex($name);
if ( $expected ne $md5val ) {
print "bad md5_hex=$md5val\nexpect hexv=$expected\nnot ";
}
print "ok $testno\n";
++$testno;
$expected = '2wWDPCnmiLWrVNXoYIpy7A';
$md5val = $c->md5_b64($name);
if ( $expected ne $md5val ) {
print "bad md5_b64=$md5val\nexpect b64v=$expected\nnot ";
}
print "ok $testno\n";
++$testno;
( run in 1.479 second using v1.01-cache-2.11-cpan-2398b32b56e )