mhash_keygen_s2k()
mhash_keygen_s2k() — Generates a key.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
The PHP manual marks this function as deprecated (since PHP 8.1): do not use it in new code.
What it does
Generates a key according to the given algo, using an user provided password.
Signature
mhash_keygen_s2k(int $algo, string $password, string $salt, int $length): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $algo | int | The hash ID used to create the key. One of the MHASH_hashname constants. |
| $password | string | An user supplied password. |
| $salt | string | Must be different and random enough for every key you generate in order to create different keys. Because salt must be known when you check the keys, it is a good idea to append the key to it. Salt has a fixed length of 8 bytes and will be padded with zeros if you supply less bytes. |
| $length | int | The key length, in bytes. |
Return value
Returns the generated key as a string, or false on error.
Example
The PHP manual ships no example for mhash_keygen_s2k(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.1.0 | This function has been deprecated. Use the hash_*() functions instead. |
All PHP 8.5 built-in functions
Reference card built from the PHP manual page mhash_keygen_s2k() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.