4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Polyfill\Php55;
19 public static function boolval($val)
24 public static function json_last_error_msg()
26 switch (json_last_error()) {
27 case JSON_ERROR_NONE: return 'No error';
28 case JSON_ERROR_DEPTH: return 'Maximum stack depth exceeded';
29 case JSON_ERROR_STATE_MISMATCH: return 'State mismatch (invalid or malformed JSON)';
30 case JSON_ERROR_CTRL_CHAR: return 'Control character error, possibly incorrectly encoded';
31 case JSON_ERROR_SYNTAX: return 'Syntax error';
32 case JSON_ERROR_UTF8: return 'Malformed UTF-8 characters, possibly incorrectly encoded';
33 default: return 'Unknown error';
38 * @author Sebastiaan Stok <s.stok@rollerscapes.net>
40 public static function hash_pbkdf2($algorithm, $password, $salt, $iterations, $length = 0, $rawOutput = false)
42 // Number of blocks needed to create the derived key
43 $blocks = ceil($length / strlen(hash($algorithm, null, true)));
46 for ($i = 1; $i <= $blocks; ++$i) {
47 $ib = $block = hash_hmac($algorithm, $salt.pack('N', $i), $password, true);
50 for ($j = 1; $j < $iterations; ++$j) {
51 $ib ^= ($block = hash_hmac($algorithm, $block, $password, true));
58 $digest = bin2hex($digest);
61 return substr($digest, 0, $length);