Apache::CryptHash - Encrypted tokens for cookies


Apache-CryptHash documentation  | view source Contained in the Apache-CryptHash distribution.

Index


NAME

Top

Apache::CryptHash - Encrypted tokens for cookies

SYNOPSIS

Top

use Apache::CryptHash;

DESCRIPTION

Top

Creates an encrypted cookie-like string with a MAC (checksum) from a hash of critical and non-critical values. The MAC is created on only the critical values. Decryption will fail if the string has been altered and the MAC does not match when the string is decrypted.

Particularly useful when using COOKIES and will do all the hard work for Apache::AuthCookie

init()

Create class reference and set passcode to the value returned by Sys::Hostname::hostname;

  my $c = Apache::CryptHash->init;	# default passcode = hostname

init takes an optional parameter

  my $c = Apache::CryptHash->init('no');

  $c->passcode('no'}		# will turn encryptation off
				# and put in Debug mode

Optionally, the passcode or debug may be set by

  $c->passcode('no')		# will turn encryptation off
                                # and put in Debug mode
  $c->passcode('newpasscode');	# change the passcode

name & passcode

Hash Header may be set to any string

  $c->name('some_string');	# default 'Secret'

Just remember to obey the rules for allowed characters in cookie strings for both name & passcode

encode()

Generate an encrypted cookie-like value from a hash. Optional invarient values may be specified for a MAC

  $c->encode(\%state, \@mac_keys).

Only the crypt secret and the mac_keys valuess are present in the MAC. What is returned is

  NAME:crypted_string (NAME.Debug:crypted_string)

where $c->pascode(somename) (default 'Secret')

decode($$$)

Decrypt and generate state hash from the encrypted hash

  $c->decode(\$cookie,\%state, \@mac_keys);

Return false if decode or MAC fails

md5_hex($)

Return the md5 hash of input string.

md5_b64($)

Return the md5 base 64 hash of input string.

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

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

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

SEE ALSO

Top

Crypt::CapnMidNite Crypt::RC4 Digest::MD5 MIME::Base64

COPYRIGHT and LICENSE

Top


Apache-CryptHash documentation  | view source Contained in the Apache-CryptHash distribution.