Lyra Orwell
Lyra Orwell

Reputation: 1276

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.

Upvotes: 2

Views: 1077

Answers (1)

manveti
manveti

Reputation: 1711

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()).

Upvotes: 3

Related Questions