Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decryption #537

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/renderer/src/progress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,28 @@ function encode(text) {
const cipher = crypto.createCipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, ENCRYPTION_IV);

const encrypted = cipher.update(text);
return CRYPTO_VERSION + Buffer.concat([encrypted, cipher.final()]).toString("hex");
return `${CRYPTO_VERSION}:${ENCRYPTION_IV.toString("hex")}:${Buffer.concat([encrypted, cipher.final()]).toString(
"hex"
)}`;
}

// Try to decode the value
function decode(text) {
if (!crypto || !/[0-9A-Fa-f]{6}/g.test(text)) return text;
if (text.slice(0, CRYPTO_VERSION.length) !== CRYPTO_VERSION) return undefined;
const [TEXT_CRYPTO_VERSION, ENCRYPTION_IV_HEX, encrypted] = text.split(":");

text = text.slice(CRYPTO_VERSION.length);
if (text.slice(0, TEXT_CRYPTO_VERSION.length) !== CRYPTO_VERSION) return undefined;

if (!crypto || !/[0-9A-Fa-f]{6}/g.test(encrypted)) return encrypted;

try {
let textParts = text.split(":");
let textParts = encrypted.split(":");
let encryptedText = Buffer.from(textParts.join(":"), "hex");
let decipher = crypto.createDecipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, ENCRYPTION_IV);
let decipher = crypto.createDecipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, Buffer.from(ENCRYPTION_IV_HEX, "hex"));
let decrypted = decipher.update(encryptedText);
decrypted = Buffer.concat([decrypted, decipher.final()]);
return decrypted.toString();
} catch {
return text;
return encrypted;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/renderer/src/stories/pages/settings/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const schema = merge(
}
);

console.log(schema);

import { Button } from "../../Button.js";
import { global } from "../../../progress/index.js";
import { merge, setUndefinedIfNotDeclared } from "../utils.js";
Expand Down
Loading