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);
    }
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);
    }
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 ) ; }
Encrypt a string.

@param string $data

@return string|null
Encrypt a string .