Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)

I have been searching for at some point the best way to encrypt and decrypt a string. Yet, a large portion of it is in 2.7 and anything that is utilizing 3.2 isn't allowing me to print it or add it to a string. 

So the thing I'm attempting to do is the accompanying:

mystring = "Hello stackoverflow!"

encoded = encode(mystring,"password")

print(encoded)

jgAKLJK34t3g (a bunch of random letters)

decoded = decode(encoded,"password")

print(decoded)

Hello stackoverflow!

Is there any case of doing this, utilizing python 3.X, and when the string is encoded it's as yet a string, no other variable type?

1 Answer

0 votes
by (26.4k points)

I experienced difficulties compiling all the most regularly referenced cryptography libraries on my Windows 7 framework and for Python 3.5. 

This is the arrangement that at last worked for me.

from cryptography.fernet import Fernet

key = Fernet.generate_key() #this is your "password"

cipher_suite = Fernet(key)

encoded_text = cipher_suite.encrypt(b"Hello stackoverflow!")

decoded_text = cipher_suite.decrypt(encoded_text)

Interested to learn the concepts of Python in detail? Come and join the python course to gain more knowledge in python

Watch this video tutorial for more information.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 7, 2020 in Python by ashely (50.2k points)

Browse Categories

...