feat(client): 添加 Python 客户端及示例应用

- 新增 python-client 模块,提供 ConfigClient 配置拉取、定时同步、变更监听
- 使用 pyaes 替代 cryptography 实现 AES 解密,避免编译问题
- 新增 python-client-demo Flask 示例应用
- .gitignore 添加 Python 相关忽略规则
This commit is contained in:
2026-02-05 21:05:19 +08:00
parent 6653c752e7
commit c31746d7d1
11 changed files with 431 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import base64
import hashlib
import pyaes
CRYPT_PREFIX = "{Cipher}"
def decrypt_config(secret: str, data: str) -> str:
if not data.startswith(CRYPT_PREFIX):
return data
encrypted = data[len(CRYPT_PREFIX):]
return decrypt_with_aes(secret, encrypted)
def decrypt_with_aes(key: str, data: str) -> str:
md5_hash = hashlib.md5(key.encode()).hexdigest()
aes_key = md5_hash[16:].encode()
cipher_text = base64.b64decode(data)
iv = b"\0" * 16
aes_cbc = pyaes.AESModeOfOperationCBC(aes_key, iv=iv)
plain_text = aes_cbc.decrypt(cipher_text)
padding = plain_text[-1]
plain_text = plain_text[:-padding]
return plain_text.decode()