PHP hash() Function: Generating Hash Values (Message Digests)

This article explains PHP's hash() function, detailing its purpose, supported algorithms, parameter usage, optional raw output, and provides a clear code example with expected hexadecimal result for generating cryptographic message digests.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP hash() Function: Generating Hash Values (Message Digests)

The hash() function in PHP returns a hash value (message digest) for a given string using a specified algorithm such as md5, sha256, or ripemd160. It can output either a lowercase hexadecimal string or raw binary data.

Parameters

algo : The hash algorithm to use (e.g., "md5", "sha256", "haval160,4").

data : The message to be hashed.

raw_output : Set to true to return raw binary data; set to false (default) to return a lowercase hexadecimal string.

Return Value

If raw_output is true, the function returns the raw binary representation of the digest; otherwise it returns the digest as a lowercase hexadecimal string.

Example

<?php
echo hash('ripemd160', 'The quick brown fox jumped over the lazy dog.');
?>

Output

ec457d0a974c48d5685a7efa03d137dc8bbde7e3
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

securityHash
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.