1、下载Crypt
pip install pycrypto
下载报错,参照这篇文章处理:https://blog.csdn.net/weixin_42880082/article/details/126230526
2、代码
import json
from Crypto.Cipher import AES
import binascii
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA256
import rsa
from Crypto.Util.Padding import pad
class Test:
def __init__(self):
self.unpad = lambda date: date[0:-ord(date[-1])]
def ecs_ecb_encrypt(self, json_string, aes_key):
raw = pad(json_string.encode('utf-8'), AES.block_size, style='pkcs7') # 选择pkcs7补全
cipher = AES.new(aes_key, AES.MODE_ECB)
encrypted = cipher.encrypt(raw)
encrypted = binascii.b2a_hex(encrypted)
encrypted = encrypted