src/Util/Crypto.php
public static function pbkdf2(
        string $algorithm,
        string $password,
        string $salt,
        int $count,
        int $length,
        bool $raw = false
    ) {
        $algorithm = \strtolower($algorithm);
        // Whitelist, or we could end up with people using CRC32.
        if (!isset(self::$hashList[$algorithm])) {
            throw new CryptoException('Algorithm is not a secure cryptographic hash function.');
        }

        if ($count <= 0 || $length <= 0) {
            throw new CryptoException('Invalid PBKDF2 parameters.');
        }

        // The output length is in NIBBLES (4-bits) if $raw_output is false!
        if (!$raw) {
            $length *= 2;
        }

        return \hash_pbkdf2($algorithm, $password, $salt, $count, $length, $raw);
    }
public static function pbkdf2(
        string $algorithm,
        string $password,
        string $salt,
        int $count,
        int $length,
        bool $raw = false
    ) {
        $algorithm = \strtolower($algorithm);
        // Whitelist, or we could end up with people using CRC32.
        if (!isset(self::$hashList[$algorithm])) {
            throw new CryptoException('Algorithm is not a secure cryptographic hash function.');
        }

        if ($count <= 0 || $length <= 0) {
            throw new CryptoException('Invalid PBKDF2 parameters.');
        }

        // The output length is in NIBBLES (4-bits) if $raw_output is false!
        if (!$raw) {
            $length *= 2;
        }

        return \hash_pbkdf2($algorithm, $password, $salt, $count, $length, $raw);
    }
public static function pbkdf2 ( string $ algorithm , string $ password , string $ salt , int $ count , int $ length , bool $ raw = false ) { $ algorithm = \ strtolower ( $ algorithm ) ; // Whitelist, or we could end up with people using CRC32. if ( ! isset ( self :: $ hashList [ $ algorithm ] ) ) { throw new CryptoException ( 'Algorithm is not a secure cryptographic hash function.' ) ; } if ( $ count <= 0 || $ length <= 0 ) { throw new CryptoException ( 'Invalid PBKDF2 parameters.' ) ; } // The output length is in NIBBLES (4-bits) if $raw_output is false! if ( ! $ raw ) { $ length *= 2 ; } return \ hash_pbkdf2 ( $ algorithm , $ password , $ salt , $ count , $ length , $ raw ) ; }
Computes the PBKDF2 password-based key derivation function.

The PBKDF2 function is defined in RFC 2898. Test vectors can be found in
RFC 6070. This implementation of PBKDF2 was originally created by Taylor
Hornby, with improvements from http://www.variations-of-shadow.com/.

@param string $algorithm The hash algorithm to use. Recommended: SHA256
@param string $password  The password.
@param string $salt      A salt that is unique to the password.
@param int    $count     Iteration count. Higher is better, but slower. Recommended: At least 1000.
@param int    $length    The length of the derived key in bytes.
@param bool   $raw       If true, the key is returned in raw binary format. Hex encoded otherwise.

@throws CryptoException

@return string A $key_length-byte key derived from the password and salt.
Computes the PBKDF2 password - based key derivation function .