public function encrypt($data)
    {
        if (!$data || !is_scalar($data)) {
            return null;
        }

        $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
        $cipher = sodium_crypto_secretbox($data, $nonce, $this->key);

        return base64_encode($nonce . $cipher);
    }