PHP7: Unknown hash algorithm: sha256

In PHP7, when I haveh a line like this:

$hash = hash("sha256", "password");

I have this warning:

Unknown hashing algorithm: sha256

In PHP 5.2.9 it worked. Is sha256 deprecated in php7? Another idea?

Notes

  • The extension "php_openssl.dll" is included.
  • hash ("sha512", "password"); // WORKS!
  • print_r( hash_algos() );

    [0] => md2 [1] => md4 [2] => md5 [3] => sha1 [4] => sha224 [5] => sha256 [6] => sha384 [7] => sha512 ...

+4
source share
4 answers

I know that you got it to work, but I wanted to add that I looked at the source code of PHP7, and there is simply no reason why it should not work every time.

In ./ext/hash/hash.cwe define our table of available hashes:

PHP_MINIT_FUNCTION(hash)
{
    // ...
    zend_hash_init(&php_hash_hashtable, 35, NULL, NULL, 1);

    // ...
    php_hash_register_algo("sha224",        &php_hash_sha224_ops);
    php_hash_register_algo("sha256",        &php_hash_sha256_ops);
    php_hash_register_algo("sha384",        &php_hash_sha384_ops);
    php_hash_register_algo("sha512",        &php_hash_sha512_ops);
    // ...
}

php_hash_register_algo() also very simple:

PHP_HASH_API void php_hash_register_algo(const char *algo, const php_hash_ops *ops) /* {{{ */
{
    size_t algo_len = strlen(algo);
    char *lower = zend_str_tolower_dup(algo, algo_len);
    zend_hash_str_add_ptr(&php_hash_hashtable, lower, algo_len, (void *) ops);
    efree(lower);
}

So what of php_hash_sha256_ops? This is defined in ./ext/hash/hash_sha.c:

const php_hash_ops php_hash_sha256_ops = {
    (php_hash_init_func_t) PHP_SHA256Init,
    (php_hash_update_func_t) PHP_SHA256Update,
    (php_hash_final_func_t) PHP_SHA256Final,
    (php_hash_copy_func_t) php_hash_copy,
    32,
    64,
    sizeof(PHP_SHA256_CTX)
};

, , PHP_SHA256Init(), PHP_SHA256Update() PHP_SHA256Final() . , sha256 .

+2

.

0

, - mod_php mpm_event apache. , non-thread-safe php7 , , , sha1 .

0

1) localhost/phpmyadmin 127.0.0.1/phpmyadmin, , , .

2). , , PHPMYADMIN.

3). , xampp wampp, .

4).

0

Source: https://habr.com/ru/post/1617864/


All Articles