fix: safeStorage 解密失败时回退到 base64 解码
密码可能在 safeStorage 不可用时以纯 base64 存储,或因 keyring 环境 变化导致无法解密。添加 try-catch 回退,避免连接时崩溃。
This commit is contained in:
@@ -11,5 +11,13 @@ export function decrypt(encoded: string): string {
|
|||||||
if (!safeStorage.isEncryptionAvailable()) {
|
if (!safeStorage.isEncryptionAvailable()) {
|
||||||
return Buffer.from(encoded, 'base64').toString('utf-8')
|
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')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user