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.
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
ec457d0a974c48d5685a7efa03d137dc8bbde7e3Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
