How do I encrypt and decrypt a string in python?

后端 未结 8 1466
忘了有多久
忘了有多久 2020-11-28 05:36

I have been looking for sometime on how to encrypt and decrypt a string. But most of it is in 2.7 and anything that is using 3.2 is not letting me print it or add it to a st

8条回答
  •  青春惊慌失措
    2020-11-28 05:52

    You may use Fernet as follows:

    from cryptography.fernet import Fernet
    key = Fernet.generate_key()
    f = Fernet(key)
    encrypt_value = f.encrypt(b"YourString")
    f.decrypt(encrypt_value)
    

提交回复
热议问题