protected function mask($data)
    {
        $out    = '';
        $length = mb_strlen($data, '8bit');
        $j      = ($this->cursor - $this->headerLength) % 4;

        for ($i = 0; $i < $length; $i++) {
            $data_octet = $this->getChar($data, $i);
            $mask_octet = $this->getChar($this->mask, $j);
            $out .= pack('C', ($data_octet ^ $mask_octet));
            $j++;
            if ($j >= 4) {
                $j = 0;
            }
        }

        return $out;
    }