public static function pbkdf2($password, $salt, $iterationCount, $derivedKeyLength, $algorithm = 'sha256')
{
$hashLength = strlen(hash($algorithm, null, true));
$keyBlocksToCompute = ceil($derivedKeyLength / $hashLength);
$derivedKey = '';
for ($block = 1; $block <= $keyBlocksToCompute; $block++) {
$iteratedBlock = hash_hmac($algorithm, $salt . pack('N', $block), $password, true);
for ($iteration = 1, $iteratedHash = $iteratedBlock; $iteration < $iterationCount; $iteration++) {
$iteratedHash = hash_hmac($algorithm, $iteratedHash, $password, true);
$iteratedBlock ^= $iteratedHash;
}
$derivedKey .= $iteratedBlock;
}
return substr($derivedKey, 0, $derivedKeyLength);
}