hexdigest#

Finalise the running hash and return the digest as a lowercase hex string.

Identical to digest except for encoding: the result is a string of lowercase hexadecimal characters, twice the length of the raw digest (40 chars for SHA-1, 64 for SHA-256, 128 for SHA-512, etc.). As with digest, the object is automatically reset after the call.

Synopsis#

my $hex = $sha->hexdigest;

What you get back#

A string of [0-9a-f] characters of length hashsize / 4.

Examples#

my $sha = Digest::SHA->new(256);
$sha->add("abc");
print $sha->hexdigest;

## ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
my $sha = Digest::SHA->new(1);
print $sha->hexdigest;

## da39a3ee5e6b4b0d3255bfef95601890afd80709   (empty-input SHA-1)
use Digest::SHA;
print Digest::SHA->new(512)->add("The quick brown fox")->hexdigest, "\n";

Edge cases#

  • Auto-resets the object, same as digest.

  • Called on an object with no input fed, returns the hex digest of the empty string (da39a3ee… for SHA-1, e3b0c442… for SHA-256).

  • Called on a non-Digest::SHA object, returns undef.

Differences from upstream#

Fully compatible with upstream Digest::SHA 6.04.

See also#

  • digest — raw-byte counterpart.

  • b64digest — unpadded Base64 counterpart.

  • sha256_hex — functional one-shot with the same output shape.