Digest::MD5
Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.
Provides MD5 hashing functionality compatible with the Digest::MD5 Perl module.
Synopsis
use Digest::MD5 qw(md5_hex md5_base64);
my $hex = md5_hex("some data");
my $base64 = md5_base64("some data");
# OO interface for incremental hashing
my $ctx = Digest::MD5->new;
$ctx->add("first chunk");
$ctx->add("second chunk");
my $digest = $ctx->hexdigest;
Functional Interface
md5($data)- Returns binary MD5 digest (16 bytes)md5_hex($data)- Returns hexadecimal MD5 digest (32 characters)md5_base64($data)- Returns base64-encoded MD5 digest (22 characters, no padding)
Object-Oriented Interface
Digest::MD5->new()- Creates a new MD5 context object$ctx->add($data, ...)- Adds data to the context$ctx->addfile($fh)- Adds data from a filehandle (not yet implemented)$ctx->digest()- Returns binary digest and resets the context$ctx->hexdigest()- Returns hex digest and resets the context$ctx->b64digest()- Returns base64 digest (no padding) and resets the context$ctx->reset()- Resets the context$ctx->clone()- Clones the context
Implementation Notes
The OO interface stores accumulated data in a blessed hash reference.
The hash uses a special key _data to store the accumulated bytes.
Computing the actual MD5 hash is done when digest(), hexdigest(), or
b64digest() is called.
This approach avoids the complexity of storing Rust state (Md5 hasher) in Perl values while maintaining compatibility with the Perl interface.
Functions
Digest
add
Appends data to the MD5 context for incremental digesting. Returns the context for method chaining.
See also: addfile, digest, hexdigest
add_bits
Adds bits to the MD5 context. The argument is a string of ‘0’ and ‘1’ characters whose length must be a multiple of 8.
addfile
Reads all data from the given filehandle and adds it to the MD5 context. Returns the context for method chaining.
b64digest
Returns the base64-encoded MD5 digest (22 characters, no padding) of the accumulated data and resets the context.
clone
Creates and returns a copy of the MD5 context, preserving accumulated data and blessed class.
context
Gets or sets the internal MD5 computation state. In get mode returns ($block_count, $state_buffer[, $unprocessed]). In set mode restores state from arguments.
See also: digest, reset, clone
digest
Returns the binary MD5 digest (16 bytes) of the accumulated data and resets the context.
See also: hexdigest, b64digest
hexdigest
Returns the hexadecimal MD5 digest (32 characters) of the accumulated data and resets the context.
md5
Computes the MD5 digest of the concatenated arguments and returns the binary digest (16 bytes).
See also: md5_hex, md5_base64
md5_base64
Computes the MD5 digest of the concatenated arguments and returns the base64-encoded digest (22 characters, no padding).
md5_hex
Computes the MD5 digest of the concatenated arguments and returns the hexadecimal digest (32 characters).
See also: md5, md5_base64
new
Creates and returns a new Digest::MD5 context object, blessed into the given class.
reset
Resets the MD5 context, discarding all accumulated data. Returns the context for method chaining.