mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-11 22:06:17 +00:00
29 lines
707 B
TypeScript
29 lines
707 B
TypeScript
import { safeStorage } from "electron";
|
|
import { logger } from "./logger";
|
|
|
|
export class Crypto {
|
|
public static encrypt(str: string) {
|
|
if (safeStorage.isEncryptionAvailable()) {
|
|
return safeStorage.encryptString(str).toString("base64");
|
|
} else {
|
|
logger.warn(
|
|
"Encrypt method returned raw string because encryption is not available"
|
|
);
|
|
|
|
return str;
|
|
}
|
|
}
|
|
|
|
public static decrypt(b64: string) {
|
|
if (safeStorage.isEncryptionAvailable()) {
|
|
return safeStorage.decryptString(Buffer.from(b64, "base64"));
|
|
} else {
|
|
logger.warn(
|
|
"Decrypt method returned raw string because encryption is not available"
|
|
);
|
|
|
|
return b64;
|
|
}
|
|
}
|
|
}
|