From bcf31e7d3a1720655355a39ffb7c1fbdf14da559 Mon Sep 17 00:00:00 2001 From: Jokul Date: Sat, 11 Jul 2026 00:03:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20safeStorage=20=E8=A7=A3=E5=AF=86?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=E5=9B=9E=E9=80=80=E5=88=B0=20base64?= =?UTF-8?q?=20=E8=A7=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 密码可能在 safeStorage 不可用时以纯 base64 存储,或因 keyring 环境 变化导致无法解密。添加 try-catch 回退,避免连接时崩溃。 --- src/main/credential.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/credential.ts b/src/main/credential.ts index 36161e0..f5f7f9e 100644 --- a/src/main/credential.ts +++ b/src/main/credential.ts @@ -11,5 +11,13 @@ export function decrypt(encoded: string): string { if (!safeStorage.isEncryptionAvailable()) { return Buffer.from(encoded, 'base64').toString('utf-8') } - return safeStorage.decryptString(Buffer.from(encoded, 'base64')) + try { + return safeStorage.decryptString(Buffer.from(encoded, 'base64')) + } catch { + // Fallback: the ciphertext may have been encoded with plain base64 + // (e.g. when safeStorage was unavailable at encryption time, or the + // OS keyring changed). Decode as plain base64 so the connection + // attempt can proceed instead of crashing. + return Buffer.from(encoded, 'base64').toString('utf-8') + } }