Unknown digest algorithm: %s

Description

The digest algorithm name passed to a hash function is not recognized by PHP’s Hash extension.

The hash(), hash_file(), and hash_hmac() functions rely on a registry of supported algorithms. When an algorithm name is not found in that registry, this warning is emitted and the function returns false.

The list of available algorithms depends on the extensions loaded at runtime. Algorithms may be added or removed depending on the PHP version and compiled extensions.

Algorithms are case-insensitive, but misspellings will still produce this error.

Example

<?php

// hash() with a valid algorithm works
hash('sha256', 'my data');

// hash() with an unknown algorithm triggers the warning
hash('unknown_algo', 'my data');

// hash_file() also triggers it
hash_file('bad_algo', '/tmp/file.txt');

// hash_hmac() too
hash_hmac('invalid', 'my data', 'secret');

?>

Literal Examples

  • Unknown digest algorithm: blowfish

  • Unknown digest algorithm: tiger

  • Unknown digest algorithm: sha3-224

Solutions

  • Check available algorithms with hash_algos() before using one.

  • Use one of the standard algorithms: md5, sha1, sha256, sha512, sha3-256.

  • Verify the algorithm is available by checking in_array($algo, hash_algos()).

  • Install or enable the required extension that provides the algorithm (e.g. hash with GOST support).

See Also

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.