perldoc > Digest

📛 NAME

Digest - Modules that calculate message digests

🚀 Quick Reference

Use CaseCommandDescription
Create MD5 digest object$md5 = Digest->new("MD5");🔨 Instantiate a new MD5 digest calculator
Create SHA-256 digest object$sha256 = Digest->new("SHA-256");🔨 Instantiate a new SHA-256 digest calculator
Add data to digest$ctx->add($data);📥 Append data to the message being hashed
Get binary digest$digest = $ctx->digest;🔢 Return the binary digest (compact, not printable)
Get hex digest$hex = $ctx->hexdigest;🔢 Return the digest as lowercase hexadecimal string
Get base64 digest (no padding)$b64 = $ctx->b64digest;🔢 Return the digest as base64 without trailing padding
HMAC-MD5$hmac = Digest->HMAC_MD5($key);🔑 Create an HMAC-MD5 digest using a key
Read file into digest$ctx->addfile($io_handle);📄 Read file handle content and append to message

📖 SYNOPSIS

$md5  = Digest->new("MD5");
$sha1 = Digest->new("SHA-1");
$sha256 = Digest->new("SHA-256");
$sha384 = Digest->new("SHA-384");
$sha512 = Digest->new("SHA-512");

$hmac = Digest->HMAC_MD5($key);

📝 DESCRIPTION

The Digest:: modules calculate digests, also called fingerprints or hashes, of some data, called a message. The digest is (usually) some small/fixed size string. The actual size of the digest depends on the algorithm used. The message is simply a sequence of arbitrary bytes or bits.

An important property of the digest algorithms is that the digest is likely to change if the message changes in some way. Another property is that digest functions are one-way functions, that is it should be hard to find a message that corresponds to some given digest. Algorithms differ in how likely and how hard, as well as how efficient they are to compute.

Note that the properties of the algorithms change over time, as the algorithms are analyzed and machines grow faster. If your application for instance depends on it being impossible to generate the same digest for a different message it is wise to make it easy to plug in stronger algorithms as the one used grows weaker. Using the interface documented here should make it easy to change algorithms later.

All Digest:: modules provide the same programming interface. A functional interface for simple use, as well as an object oriented interface that can handle messages of arbitrary length and which can read files directly.

The digest can be delivered in three formats:

The functional interface is simply importable functions with the same name as the algorithm. The functions take the message as argument and return the digest. Example:

use Digest::MD5 qw(md5);
$digest = md5($message);

There are also versions of the functions with _hex or _base64 appended to the name, which returns the digest in the indicated form.

🔧 OO INTERFACE

The following methods are available for all Digest:: modules:

⚡ Digest Speed

This table gives an indication of relative speed of different algorithms. Sorted by throughput based on a benchmark (ActivePerl-5.8.3, Linux P4 2.8 GHz CPU, Apr 2004).

🔢 Algorithm📏 Size📦 Implementation🚀 MB/s
MD4128Digest::MD4 v1.3165.0
MD5128Digest::MD5 v2.3398.8
SHA-256256Digest::SHA2 v1.1.066.7
SHA-1160Digest::SHA v4.3.158.9
SHA-1160Digest::SHA1 v2.1048.8
SHA-256256Digest::SHA v4.3.141.3
Haval-256256Digest::Haval256 v1.0.439.8
SHA-384384Digest::SHA2 v1.1.019.6
SHA-512512Digest::SHA2 v1.1.019.3
SHA-384384Digest::SHA v4.3.119.2
SHA-512512Digest::SHA v4.3.119.2
Whirlpool512Digest::Whirlpool v1.0.213.0
MD2128Digest::MD2 v2.039.5
Adler-3232Digest::Adler32 v0.031.3
CRC-1616Digest::CRC v0.051.1
CRC-3232Digest::CRC v0.051.1
MD5128Digest::Perl::MD5 v1.51.0
CRC-CCITT16Digest::CRC v0.050.8

The last 5 entries are pure Perl implementations, explaining their slower speed.

📚 SEE ALSO

Digest::Adler32, Digest::CRC, Digest::Haval256, Digest::HMAC, Digest::MD2, Digest::MD4, Digest::MD5, Digest::SHA, Digest::SHA1, Digest::SHA2, Digest::Whirlpool

New digest implementations should consider subclassing from Digest::base.

MIME::Base64

http://en.wikipedia.org/wiki/Cryptographic_hash_function

✍️ AUTHOR

Gisle Aas <gisle AT aas.no>

The Digest:: interface is based on the interface originally developed by Neil Winton for his MD5 module.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Copyright 1998-2006 Gisle Aas.
Copyright 1995,1996 Neil Winton.
Digest
📛 NAME 🚀 Quick Reference 📖 SYNOPSIS 📝 DESCRIPTION 🔧 OO INTERFACE ⚡ Digest Speed 📚 SEE ALSO ✍️ AUTHOR

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-09 14:19 @216.73.216.150
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^