protected function initBufferEncryption($data, $key)
    {
        $data   = (binary) $data;
        $header = $this->buildHeader();
        $nonce  = new Buffer(24);
        $nonce->write((string) $header, 0);

        $data = \Sodium\crypto_secretbox($data, (string) $nonce, $key);

        $this->buffer = new Buffer(strlen((string) $header) + strlen($data));
        $this->buffer->write((string) $header, 0);
        $this->buffer->write($data, 12);
    }