def index():
key=b"key"
iv=b"iv"
# 创建 AES 加密实例
cipher = AES.new(key, AES.MODE_CBC, iv)
tenant = "tenant"
account = "account" # 前端获取的子账号唯一标识,不可写死,不可为中文。子账号数有限制
# data = int(time.time()) # 当前时间戳
sData = str(time.time())
content = tenant + "+" + account + "+" + sData
# 对内容进行加密
encrypted = cipher.encrypt(pad(content.encode(), AES.block_size))
sig = b64encode(encrypted).decode("utf-8")
# 将 sig 进行 URL 编码
sig = urllib.parse.quote(sig, safe="")
print(f"sig = {sig}")
print("===========")
# 解密处理(如果不需要可以忽略)
token = sig
# 取消 URL 转义
token = urllib.parse.unquote(token)
# 将 sig 进行 BASE64 解码
encrypted_content = b64decode(token)
# 使用相同的密钥和 iv 解密
cipher = AES.new(key, AES.MODE_CBC, iv)
decrypted = unpad(cipher.decrypt(encrypted_content), AES.block_size)
# 解密后的结果
encoder = decrypted.decode("utf-8")
print(f"encoder = {encoder}")
# 返回加密结果
return sig
# 调用函数
sig = index()