lithium\util\String::hash()
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 thehash_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 specifiedhash_hmac()
will be used to hash the string, instead ofhash()
, with'key'
being used as the message key.'raw'
boolean: Iftrue
, outputs the raw binary result of the hash operation. Defaults tofalse
.
Returns
stringReturns a hashed string.
Links
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']);
}