Crypt::Mac::HMAC - Message authentication code HMAC
### Functional interface: use Crypt::Mac::HMAC qw( hmac hmac_hex ); # calculate MAC from string/buffer $hmac_raw = hmac($hash_name, $key, 'data string'); $hmac_hex = hmac_hex($hash_name, $key, 'data string'); $hmac_b64 = hmac_b64($hash_name, $key, 'data string'); ### OO interface: use Crypt::Mac::HMAC; $d = Crypt::Mac::HMAC->new($hash_name, $key); $d->add('any data'); $d->addfile('filename.dat'); $d->addfile(*FILEHANDLE); $result_raw = $d->mac; # raw bytes $result_hex = $d->hexmac; # hexadecimal form $result_b64 = $d->b64mac; # Base64 form
Provides an interface to the HMAC message authentication code (MAC) algorithm.
Nothing is exported by default.
You can export selected functions:
use Crypt::Mac::HMAC qw(hmac hmac_hex );
Or all of them at once:
use Crypt::Mac::HMAC ':all';
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a binary string.
$hmac_raw = hmac($hash_name, $key, 'data string'); #or $hmac_raw = hmac($hash_name, $key, 'any data', 'more data', 'even more data');
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a hexadecimal string.
$hmac_hex = hmac($hash_name, $key, 'data string'); #or $hmac_hex = hmac($hash_name, $key, 'any data', 'more data', 'even more data');
Logically joins all arguments into a single string, and returns its HMAC message authentication code encoded as a BASE64 string.
$hmac_b64 = hmac($hash_name, $key, 'data string'); #or $hmac_b64 = hmac($hash_name, $key, 'any data', 'more data', 'even more data');
The OO interface provides the same set of functions as Crypt::Mac.
$d = Crypt::Mac::HMAC->new($hash_name, $key);
$d->clone();
$d->reset();
$d->add('any data'); #or $d->add('any data', 'more data', 'even more data');
$d->addfile('filename.dat'); #or $d->addfile(*FILEHANDLE);
$result_raw = $d->mac();
$result_hex = $d->hexmac();
$result_base64 = $d->b64mac();
To install CryptX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CryptX
CPAN shell
perl -MCPAN -e shell install CryptX
For more information on module installation, please visit the detailed CPAN module installation guide.