#!/usr/bin/env python# -*- coding: utf-8 -*-# Created by weilai on 2017/04/14from Cryptodome.Cipher import AESfrom Cryptodome.Random import get_random_bytesimport base64# declared outside of all functionskey = get_random_bytes(16)tag = Nonenonce = Nonedef encrypt(data): global tag, nonce byte_data = data.encode(encoding="utf-8") cipher = AES.new(key, AES.MODE_EAX) nonce = cipher.nonce cipher_text, tag = cipher.encrypt_and_digest(byte_data) return cipher_textdef decrypt(data): global tag, nonce cipher = AES.new(key, AES.MODE_EAX, nonce) decrypt_text = cipher.decrypt_and_verify(data, tag) return decrypt_textr = encrypt('超级大坏蛋')b64r = base64.b64encode(r)print(b64r)b64b = base64.b64decode(b64r)rr = decrypt(b64b)print(rr.decode())