17 lines
505 B
TypeScript
17 lines
505 B
TypeScript
// src/main/credential.ts
|
|
import { safeStorage } from 'electron'
|
|
|
|
export function encrypt(text: string): string {
|
|
if (!safeStorage.isEncryptionAvailable()) {
|
|
return Buffer.from(text).toString('base64')
|
|
}
|
|
return safeStorage.encryptString(text).toString('base64')
|
|
}
|
|
|
|
export function decrypt(encoded: string): string {
|
|
if (!safeStorage.isEncryptionAvailable()) {
|
|
return Buffer.from(encoded, 'base64').toString('utf-8')
|
|
}
|
|
return safeStorage.decryptString(Buffer.from(encoded, 'base64'))
|
|
}
|