核心功能: - SSH终端: 密码/密钥认证、XTerm.js终端、多主题配色、IP高亮 - SFTP管理: 双栏文件管理、上传下载、传输队列 - 端口转发: 本地/远程转发、SOCKS5动态代理、规则管理 架构改进: - 拆分大型组件 (SFTPView/TabBar/Sidebar) - 添加统一日志和错误处理 - 修复React严格模式下的终端黑屏问题 UI更新: - 新增端口转发视图 - 更新UI预览文档 - 左侧栏右键菜单支持SFTP快捷打开
44 lines
1007 B
TypeScript
44 lines
1007 B
TypeScript
import { app } from 'electron'
|
|
import path from 'path'
|
|
import fs from 'fs'
|
|
import crypto from 'crypto'
|
|
import { createLogger } from '../utils/logger'
|
|
|
|
const logger = createLogger('KeyService')
|
|
|
|
const KEY_FILE = 'encryption.key'
|
|
|
|
export class KeyService {
|
|
private key: string | null = null
|
|
|
|
// 获取或创建主密钥
|
|
getMasterKey(): string {
|
|
if (this.key) return this.key
|
|
|
|
const keyPath = path.join(app.getPath('userData'), KEY_FILE)
|
|
|
|
// 尝试读取现有密钥
|
|
if (fs.existsSync(keyPath)) {
|
|
try {
|
|
this.key = fs.readFileSync(keyPath, 'utf8').trim()
|
|
return this.key
|
|
} catch (error) {
|
|
logger.error('Failed to read master key:', error)
|
|
}
|
|
}
|
|
|
|
// 生成新密钥
|
|
this.key = crypto.randomBytes(32).toString('hex')
|
|
fs.writeFileSync(keyPath, this.key, { mode: 0o600 })
|
|
return this.key
|
|
}
|
|
|
|
// 清除密钥(登出时)
|
|
clearKey(): void {
|
|
this.key = null
|
|
}
|
|
}
|
|
|
|
// 全局单例
|
|
export const keyService = new KeyService()
|