public static function generate($Z, $algorithm, $encryption_key_size, $apu = '', $apv = '')
{
$apu = !empty($apu) ? Base64Url::decode($apu) : '';
$apv = !empty($apv) ? Base64Url::decode($apv) : '';
$encryption_segments = [self::toInt32Bits(1), $Z, self::toInt32Bits(mb_strlen($algorithm, '8bit')) . $algorithm, self::toInt32Bits(mb_strlen($apu, '8bit')) . $apu, self::toInt32Bits(mb_strlen($apv, '8bit')) . $apv, self::toInt32Bits($encryption_key_size), ''];
$input = implode('', $encryption_segments);
$hash = hash('sha256', $input, true);
$kdf = mb_substr($hash, 0, $encryption_key_size / 8, '8bit');
return $kdf;
}