* @param $str The string to be hashed
* @return $hash The hash from string $str
* @throws InvalidArgumentException If a parameter is not valid
- * @throws LogicException If proper extension ext-mhash is not loaded
+ * @throws LogicException If proper extension hash is not loaded
*/
public static final function hash (string $str) {
// Validate parameter/mhash extension
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRYPTO-UTILS: str=%s - CALLED!', $str));
if (empty($str)) {
// Throw IAE
throw new InvalidArgumentException('Parameter "str" is empty');
- } elseif (!extension_loaded('mhash')) {
+ } elseif (!extension_loaded('hash')) {
// Should be there
- throw new LogicException('Extension ext-mhash not loaded');
+ throw new LogicException('Extension ext-hash not loaded');
}
// Hash given string with (better secure) hasher
- $hash = bin2hex(mhash(MHASH_SHA256, $str));
+ $hash = hash('sha256', $str, true);
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CRYPTO-UTILS: hash(%d){}=%s - EXIT!', strlen($hash), bin2hex($hash)));
return $hash;
}