Minor modifies

This commit is contained in:
Remik1r3n
2025-01-23 19:49:10 +08:00
parent 6e05b211ac
commit a714fc5655
4 changed files with 21 additions and 34 deletions

View File

@@ -17,17 +17,18 @@ aesKeyPrism = "A;mv5YUpHBK3YxTy5KB^[;5]C2AL50Bq"
aesIVPrism = "9FM:sd9xA91X14v]"
class AESPKCS7:
# 实现了 maimai 通讯所用的 AES 加密的类
def __init__(self, key: str, iv: str):
self.key = key.encode('utf-8')
self.iv = iv.encode('utf-8')
self.mode = AES.MODE_CBC
# 加密
def encrypt(self, content: bytes) -> bytes:
cipher = AES.new(self.key, self.mode, self.iv)
content_padded = pad(content, AES.block_size)
encrypted_bytes = cipher.encrypt(content_padded)
return encrypted_bytes
# 解密
def decrypt(self, encrypted_content: bytes) -> str:
cipher = AES.new(self.key, self.mode, self.iv)
decrypted_padded = cipher.decrypt(encrypted_content)