默认的

django=2.2 version
This commit is contained in:
向乐🌌
2021-04-19 08:41:22 +08:00
parent ffbe96425d
commit d8ac7552a6
10 changed files with 410 additions and 11 deletions

View File

@@ -1,4 +1,11 @@
from cryptography.fernet import Fernet
import os
import random
try:
from cryptography.fernet import Fernet
except ImportError:
os.system('pip3 install cryptography')
from cryptography.fernet import Fernet
class Crypto(object):
@@ -6,11 +13,6 @@ class Crypto(object):
def __init__(self, key):
self.factory = Fernet(key)
@staticmethod
def generate_key():
key = Fernet.generate_key()
print(key)
# 加密
def encrypt(self, string):
token = str(self.factory.encrypt(string.encode('utf-8')), 'utf-8')
@@ -20,3 +22,8 @@ class Crypto(object):
def decrypt(self, token):
string = self.factory.decrypt(bytes(token.encode('utf-8'))).decode('utf-8')
return string
if __name__ == '__main__':
key = Fernet.generate_key()
print(key)