```{index} single: digest; Digest::SHA function ``` ```{index} single: Digest::SHA::digest; Perl function ``` # digest Finalise the running hash and return the raw binary digest. Completes the SHA computation on whatever bytes have been fed in so far (via `add`, `addfile`, `add_bits`) and returns the result as a byte string. After `digest` returns, the object is automatically reset, so you can feed a new message into the same object without calling `reset` explicitly. The digest is returned as raw bytes — the fixed length of the chosen algorithm (20 bytes for SHA-1, 32 for SHA-256, 64 for SHA-512, and so on). If you want a printable form, use `hexdigest` or `b64digest` instead of converting yourself. ## Synopsis ```perl my $bytes = $sha->digest; ``` ## What you get back A scalar holding the raw digest bytes. `length` equals `hashsize / 8`. ## Examples ```perl my $sha = Digest::SHA->new(256); $sha->add("abc"); my $raw = $sha->digest; print length $raw; # 32 ``` ```perl my $sha = Digest::SHA->new(1); $sha->add("hello"); my $a = $sha->digest; $sha->add("world"); # fresh message after auto-reset my $b = $sha->digest; ``` ```perl use Digest::SHA; my $raw = Digest::SHA->new(256)->add($data)->digest; ``` ## Edge cases - Called on an object with no input fed, returns the digest of the empty string. - The auto-reset is unconditional: do not assume the hash state is preserved after `digest` returns. - Called on a non-`Digest::SHA` object, returns `undef`. ## Differences from upstream Fully compatible with upstream `Digest::SHA` {{ upstream.Digest_SHA }}. ## See also - `hexdigest` — same digest, lowercase hex string. - `b64digest` — same digest, unpadded Base64 string. - `clone` — take a snapshot before finalising if you want to keep hashing.