Q:

Passing a Variable to be Encrypted Fernet Python

I am trying to pass a Variable into the encrypt method. The encryption method is the Fernet encryption method from python cryptography.
Var = "Hello World"
Ecy = Fernet(Key)
token = Ecy.encrypt(b'Var')

However this encrypts the word Var instead of the variable.
Any help would be appreciated.

A:

You just pass in the variable itself: Ecy.encrypt(Var).
However, if you're using python3, then all strings are unicode, so you have to encode your string variable to bytes (which python2 strings are by default), like Ecy.encrypt(Var.encode()).

