md5_hex#

One-shot MD5 digest, returned as a 32-character lowercase hex string.

Synopsis#

use Digest::MD5 qw(md5_hex);
my $hex = md5_hex($data);              # 32 chars
my $hex = md5_hex($a, $b, $c);         # md5_hex($a.$b.$c)

What you get back#

A 32-character ASCII string containing only 0-9 and a-f. This is the encoding used by md5sum, HTTP ETag headers, and virtually every human-readable checksum format. All arguments are concatenated before hashing.

Examples#

The canonical one-liner:

use Digest::MD5 qw(md5_hex);
print md5_hex("foobarbaz"), "\n";

## 6df23dc03f9b54cc38a0fc1483df6e21

Compose a cache key from structured data:

my $key = md5_hex($user_id, "|", $query, "|", $locale);

Digest bytes from a multi-byte string via UTF-8 encoding:

use Encode qw(encode_utf8);
my $hex = md5_hex(encode_utf8("abc\x{300}"));

## 8c2d46911f3f5a326455f0ed7a8ed3b3

Edge cases#

  • md5_hex() with no arguments returns d41d8cd98f00b204e9800998ecf8427e.

  • Wide-character arguments croak; see md5 for the fix.

  • Result is always lowercase. Call uc if a tool requires uppercase hex.

Differences from upstream#

Fully compatible with upstream Digest::MD5 2.58.

See also#

  • md5 — same digest as raw bytes

  • md5_base64 — same digest, shorter base64 form

  • hexdigest — OO form over a reusable context

  • add — feed data incrementally when you cannot fit it in memory