update
This commit is contained in:
parent
516177e426
commit
24c81035e8
|
|
@ -55,6 +55,11 @@ def decrypt_json(token: str) -> dict[str, Any]:
|
||||||
if not token:
|
if not token:
|
||||||
return {}
|
return {}
|
||||||
token = token.strip()
|
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
|
# 兼容:历史/手工输入导致误存明文 JSON
|
||||||
if token.startswith("{"):
|
if token.startswith("{"):
|
||||||
|
|
@ -66,6 +71,10 @@ def decrypt_json(token: str) -> dict[str, Any]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 兼容:末尾 padding '=' 被裁剪导致 base64 解码失败(len % 4 != 0)
|
# 兼容:末尾 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:
|
if token and (len(token) % 4) != 0:
|
||||||
token = token + ("=" * (-len(token) % 4))
|
token = token + ("=" * (-len(token) % 4))
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue