b64digest#
Finalise the context and return the digest as a 22-char base64 string.
Synopsis#
my $b64 = $ctx->b64digest; # 22 chars, no padding
What you get back#
A 22-character string using the standard base64 alphabet
A-Z a-z 0-9 + /. The result is not padded with =; the
full base64 encoding of 16 bytes would be 24 characters, but the
tail is fixed so the padding is redundant. Append "==" yourself
if an interop partner strictly requires multiples of 4.
Base64 gives you a compact, one-line-friendly identifier that is roughly 30% shorter than hex while still printable. Common in cache keys, URL query parameters, and condensed log formats.
b64digest is destructive: the context is reset after use.
Examples#
Compact digest for a cache key:
my $key = Digest::MD5->new->add($url)->b64digest;
Pad to a multiple of 4 for strict base64 consumers:
my $padded = Digest::MD5->new->add($data)->b64digest . "==";
Peek without consuming:
my $snapshot = $ctx->clone->b64digest;
Edge cases#
Empty context →
1B2M2Y8AsgTpgAmY7PhCfg(the MD5 of the empty string in base64).Contains
/and+, so the result is not safe to drop into a URL path without further encoding — use URL-safe base64 for that (substitute-for+and_for/).Resets the context after returning.
Differences from upstream#
Fully compatible with upstream Digest::MD5 2.58.
See also#
digest— raw byteshexdigest— hex-encoded digest (longer but URL-safe)md5_base64— one-shot functional formclone— preserve the context before finalising