b64digest#

Finalise the running hash and return the digest as an unpadded Base64 string.

Identical to digest except that the result is the standard Base64 encoding of the digest without trailing = padding. The length depends on algorithm: 27 characters for SHA-1, 43 for SHA-256, 86 for SHA-512, etc. As with digest and hexdigest, the object is reset after the call.

תקציר#

my $b64 = $sha->b64digest;

מה מוחזר#

A Base64 string using the standard alphabet, with no = padding.

דוגמאות#

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

## ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0
## Compact integrity tag for a message body:

my $tag = Digest::SHA->new(256)->add($body)->b64digest;
use Digest::SHA;
print Digest::SHA->new(512)->add("hello")->b64digest, "\n";

מקרי קצה#

  • Auto-resets the object.

  • Returned string never contains = - reattach padding yourself if you need to decode against a strict Base64 parser that requires it.

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

הבדלים מן ה-upstream#

Fully compatible with upstream Digest::SHA 6.04.

ראו גם#

  • digest - raw-byte counterpart.

  • hexdigest - hexadecimal counterpart.

  • sha256_base64 - functional one-shot with the same output shape.