PHP Hash Functions

About This Index
This page is the PHP Hash Functions index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn what a hash is and which function to pick on /php/hash. Use this page when you need a specific helper such as hash(), hash_hmac(), or hash_equals().
Start with hash() and hash_hmac()—then learn hash_equals() for safe comparison and hash_init() for large data.
How to Call a Hash Function
Hash helpers are global functions—pass an algorithm name and your data:
$digest = hash('sha256', 'hello');
$mac = hash_hmac('sha256', 'hello', $secretKey);
$file = hash_file('sha256', $path);
$ctx = hash_init('sha256');
hash_update($ctx, 'Hello, ');
hash_update($ctx, 'World');
$digest = hash_final($ctx);
if (hash_equals($expected, $received)) {
echo 'Valid';
} PHP Hash Functions Table
All function guides in this PHP tutorial series (15 tutorials in 5 categories).
Hash data
2 functionsCreate a hash from a string or from the contents of a file.
| Function | Description | Tutorial |
|---|---|---|
hash() | Generate a hash value of a string, such as sha256 or md5. | Try it |
hash_file() | Generate a hash value of a file's contents. | Try it |
HMAC (keyed hashes)
2 functionsSign data with a secret key so it cannot be forged or changed.
| Function | Description | Tutorial |
|---|---|---|
hash_hmac() | Generate a keyed hash value using the HMAC method. | Try it |
hash_hmac_file() | Generate a keyed hash value of a file using the HMAC method. | Try it |
Incremental hashing
6 functionsBuild a hash in pieces from strings, files or streams.
| Function | Description | Tutorial |
|---|---|---|
hash_init() | Initialize an incremental hashing context. | Try it |
hash_update() | Pump data into an active hashing context. | Try it |
hash_update_file() | Pump data into an active hashing context from a file. | Try it |
hash_update_stream() | Pump data into an active hashing context from an open stream. | Try it |
hash_copy() | Copy a hashing context so it can be reused in two directions. | Try it |
hash_final() | Finalize an incremental hash and return the result. | Try it |
Keys & safe comparison
3 functionsDerive keys from secrets and compare hashes without timing leaks.
| Function | Description | Tutorial |
|---|---|---|
hash_pbkdf2() | Generate a PBKDF2 key derivation of a supplied password. | Try it |
hash_hkdf() | Generate an HKDF key derivation of a supplied key input. | Try it |
hash_equals() | Compare two strings in constant time to avoid timing attacks. | Try it |
Algorithm lists
2 functionsSee which algorithms your PHP supports.
| Function | Description | Tutorial |
|---|---|---|
hash_algos() | Return a list of the hashing algorithms registered in PHP. | Try it |
hash_hmac_algos() | Return a list of the algorithms that can be used with HMAC. | Try it |
Frequently Asked Questions
Start with hash()
Open the first guide—syntax, examples, and FAQs.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful
