1,安装依赖

pip install cryptography

2,生成秘钥

from cryptography.fernet import Fernet
#秘钥#随机生成秘钥  cipher_key = Fernet.generate_key()
cipher_key ='pXVAHabI4HADuM-fyVogxwV5rHRN1pZe-QQ3yM9ZvPg='

3,加密(‘123‘为要加密的对象)

a = Fernet(cipher_key).encrypt(“123”.encode()).decode()
print(a)

运行结果:
gAAAAABcmrvXiWdU9ICuUGDQoYgEQuqv0lL8BpQWRot3gJJJIGAwJlgDOKrmx8JH6mpbTfG9AdUTfUZ0eHNrXXDohCSXb87RqA==

4,解密:

b = Fernet(cipher_key).decrypt(a.encode()).decode()
print(b)

运行结果:
123

 

相关文章:

  • 2021-09-19
  • 2021-05-21
  • 2021-06-17
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-03-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-27
  • 2021-05-20
  • 2021-05-18
相关资源
相似解决方案