How do I encrypt and decrypt a string in python?

后端 未结 8 1463
忘了有多久
忘了有多久 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 06:10

    I had troubles compiling all the most commonly mentioned cryptography libraries on my Windows 7 system and for Python 3.5.

    This is the solution that finally 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)
    

提交回复
热议问题