# coding: utf-8
#
import os
from config.config import aes_args
import base64
from cryptography.fernet import Fernet
def get_aes_key():
key = base64.b64decode(aes_args.get("key")).decode("utf8")
return key
cipher = Fernet(get_aes_key())
#key解密
#加密
def aes_cbc_encrypt(message):
encrypted_text=cipher.encrypt(bytes("{}".format(message),encoding="utf8"))
return encrypted_text
#解密
def aes_cbc_decrypt(message):
decrypted_text = cipher.decrypt(bytes("{}".format(message),encoding="utf8"))
return decrypted_text.decode("utf8")
使用
import random
import base64
import unittest
import time
from config.config import aes_args
from AES.AESCal import aes_cbc_encrypt,get_aes_key,aes_cbc_decrypt
if __name__=="__main__":
input=input("请输入要加密的信息\n")
code=aes_cbc_encrypt(input)
print(code.decode("utf8"))