fix(card): 修复cic搜卡失败,增加响应data解密处理
This commit is contained in:
@@ -4,10 +4,12 @@
|
||||
# @Software : PyCharm
|
||||
# @Author : xingc
|
||||
# @Desc :
|
||||
import asyncio
|
||||
import base64
|
||||
import functools
|
||||
import random
|
||||
import string
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import unpad
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
@@ -73,3 +75,38 @@ def format_date(date: datetime | None) -> str | None:
|
||||
return date
|
||||
else:
|
||||
return date.strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
|
||||
def decrypt_aes_cbc(ciphertext_b64, key_str, iv_str):
|
||||
"""
|
||||
等效于 Node.js CryptoJS 的解密实现
|
||||
|
||||
参数:
|
||||
ciphertext_b64: Base64编码的密文
|
||||
key_str: 密钥字符串(UTF-8编码)
|
||||
iv_str: 初始化向量字符串(UTF-8编码)
|
||||
|
||||
返回:
|
||||
解密后的明文(UTF-8字符串)
|
||||
"""
|
||||
# 将密钥和IV从UTF-8字符串转换为bytes
|
||||
key = key_str.encode('utf-8')
|
||||
iv = iv_str.encode('utf-8')
|
||||
|
||||
# 确保密钥和IV长度正确
|
||||
if len(key) not in [16, 24, 32]:
|
||||
raise ValueError("密钥长度必须是16(AES-128), 24(AES-192)或32(AES-256)字节")
|
||||
|
||||
if len(iv) != 16:
|
||||
raise ValueError("IV长度必须是16字节")
|
||||
|
||||
# 解码Base64密文
|
||||
ciphertext = base64.b64decode(ciphertext_b64)
|
||||
|
||||
# 创建解密器
|
||||
cipher = AES.new(key, AES.MODE_CBC, iv)
|
||||
|
||||
# 解密并去除PKCS7填充
|
||||
decrypted = unpad(cipher.decrypt(ciphertext), AES.block_size)
|
||||
|
||||
return decrypted.decode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user