perldoc > Digest::HMAC

๐Ÿท๏ธ NAME

Digest::HMAC - Keyed-Hashing for Message Authentication

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Functional HMAC ๐Ÿงชhmac($data, $key, \&myhash)Compute HMAC with a given hash function
Functional HMAC (hex) ๐Ÿงชhmac_hex($data, $key, \&myhash)Compute HMAC and return hex string
OO style instantiation ๐ŸงฑDigest::HMAC->new($key, "Digest::MyHash")Create HMAC object with key and digest class
Add data โž•$hmac->add($data)Feed data to the HMAC object
Add file data ๐Ÿ“$hmac->addfile(*FILE)Feed data from a filehandle
Binary digest ๐Ÿ”’$hmac->digestGet the raw binary digest
Hex digest ๐Ÿ”ข$hmac->hexdigestGet the digest as a hex string
Base64 digest ๐Ÿ“ฆ$hmac->b64digestGet the digest as a Base64 string
Optional blocksize ๐ŸงฉDigest::HMAC->new($key, "Digest::Foo", $blocksize)Specify custom compression block size

๐Ÿ“ SYNOPSIS

# Functional style
use Digest::HMAC qw(hmac hmac_hex);
$digest = hmac($data, $key, \&myhash);
print hmac_hex($data, $key, \&myhash);
# OO style
use Digest::HMAC;
$hmac = Digest::HMAC->new($key, "Digest::MyHash");

$hmac->add($data);
$hmac->addfile(*FILE);

$digest = $hmac->digest;
$digest = $hmac->hexdigest;
$digest = $hmac->b64digest;

๐Ÿ“– DESCRIPTION

HMAC is used for message integrity checks ๐Ÿ” between two parties that share a secret key ๐Ÿ”‘, and works in combination with some other Digest algorithm, usually MD5 or SHA-1. The HMAC mechanism is described in RFC 2104.

HMAC follow the common "Digest::" interface, but the constructor takes the secret key and the name of some other simple "Digest::" as argument.

The hmac() and hmac_hex() functions and the Digest::HMAC->new() constructor takes an optional ๐Ÿ“ฆ $blocksize argument as well. The HMAC algorithm assumes the digester to hash by iterating a basic compression function on blocks of data and the $blocksize should match the byte-length of such blocks.

The default $blocksize is 64 which is suitable for the MD5 and SHA-1 digest functions. For stronger algorithms the blocksize probably needs to be increased.

๐Ÿ”— SEE ALSO

๐Ÿ‘ค MAINTAINER

Andrew Rodland <arodland AT cpan.org>

๐Ÿ‘ฅ ORIGINAL AUTHORS

Graham Barr <gbarr AT ti.com>, Gisle Aas <gisle AT aas.no>

Digest::HMAC
๐Ÿท๏ธ NAME ๐Ÿš€ Quick Reference ๐Ÿ“ SYNOPSIS ๐Ÿ“– DESCRIPTION ๐Ÿ”— SEE ALSO ๐Ÿ‘ค MAINTAINER ๐Ÿ‘ฅ ORIGINAL AUTHORS

Generated by phpman v4.9.25-25-g40dbf62 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-17 04:58 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format