Uses PHP's hashing functions to create a hash of the string provided, using the options
specified. The default hash algorithm is SHA-512.
Parameters
- string $string The string to hash.
- array $options Supported options: - `'type'` _string_: Any valid hashing algorithm. See the `hash_algos()` function to determine which are available on your system. - `'salt'` _string_: A _salt_ value which, if specified, will be prepended to the string. - `'key'` _string_: If specified `hash_hmac()` will be used to hash the string, instead of `hash()`, with `'key'` being used as the message key. - `'raw'` _boolean_: If `true`, outputs the raw binary result of the hash operation. Defaults to `false`.
Returns
string Returns a hashed string.Source
public static function hash($string, array $options = array()) {
$defaults = array(
'type' => 'sha512',
'salt' => false,
'key' => false,
'raw' => false
);
$options += $defaults;
if ($options['salt']) {
$string = $options['salt'] . $string;
}
if ($options['key']) {
return hash_hmac($options['type'], $string, $options['key'], $options['raw']);
}
return hash($options['type'], $string, $options['raw']);
}