This commit is contained in:
Marsway 2026-01-05 17:18:23 +08:00
parent 516177e426
commit 24c81035e8
1 changed files with 9 additions and 0 deletions

View File

@ -55,6 +55,11 @@ def decrypt_json(token: str) -> dict[str, Any]:
if not token:
return {}
token = token.strip()
# 常见脏数据:被包了引号
if (token.startswith('"') and token.endswith('"')) or (token.startswith("'") and token.endswith("'")):
token = token[1:-1].strip()
# 常见脏数据:中间混入换行/空白(复制粘贴/渲染导致)
token = "".join(token.split())
# 兼容:历史/手工输入导致误存明文 JSON
if token.startswith("{"):
@ -66,6 +71,10 @@ def decrypt_json(token: str) -> dict[str, Any]:
pass
# 兼容:末尾 padding '=' 被裁剪导致 base64 解码失败len % 4 != 0
data_len = len(token.rstrip("="))
# base64 非 padding 字符长度为 4n+1 时不可恢复:大概率是 token 被截断/丢字符
if data_len % 4 == 1:
raise ValueError("Invalid secret_cfg token (looks truncated). Please re-save secret_cfg to re-encrypt.")
if token and (len(token) % 4) != 0:
token = token + ("=" * (-len(token) % 4))
try: