import base64
from cryptography.fernet import Fernet
key = Fernet.generate_key()
def jiami_aes_Fernet(self,key,text,to_str=True):
f1_obj = Fernet(key)
mes = bytes(text,encoding='utf-8')
jiami = f1_obj.encrypt(mes)
if to_str:
jiami = str(base64.b64encode(jiami), encoding='utf-8')
return jiami
def jiemi_aes_Fernet(self,key,text):
f1_obj = Fernet(key)
if isinstance(text,str):
text = base64.b64decode(text)
jiemi = f1_obj.decrypt(text).decode('utf-8')
return jiemi
浙公网安备 33010602011771号