第三方python 加密库 --- cryptography

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

 

posted @ 2019-03-27 07:58  Xcsg  Views(3114)  Comments(0Edit  收藏  举报