Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 1, 2023
1 parent 6a4eb70 commit 37680c9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/renderer/src/progress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,33 @@ import * as operations from "./operations";
export * from "./update";

const CRYPTO_VERSION = "0.0.1"; // NOTE: Update to wipe values created using an outdated encryption algorithm
const CRYPTO_ALGORITHM = 'aes-256-cbc';
const CRYPTO_ALGORITHM = "aes-256-cbc";
const IV_LENGTH = 16;
const KEY_LENGTH = 32;
const ENCRYPTION_KEY = Buffer.concat([Buffer.from(homeDirectory), Buffer.alloc(KEY_LENGTH)], KEY_LENGTH)
const ENCRYPTION_KEY = Buffer.concat([Buffer.from(homeDirectory), Buffer.alloc(KEY_LENGTH)], KEY_LENGTH);

const iv = crypto.randomBytes(IV_LENGTH);

function encode(text) {
if (!crypto) return text;
const cipher = crypto.createCipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, iv);
const encrypted = cipher.update(text);
return CRYPTO_VERSION + Buffer.concat([encrypted, cipher.final()]).toString('hex');

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

console.log('test', encode('test'), decode(encode('test')))
console.log("test", encode("test"), decode(encode("test")));

// 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;

text = text.slice(CRYPTO_VERSION.length)
text = text.slice(CRYPTO_VERSION.length);

try {
let textParts = text.split(':');
let encryptedText = Buffer.from(textParts.join(':'), 'hex');
let textParts = text.split(":");
let encryptedText = Buffer.from(textParts.join(":"), "hex");
let decipher = crypto.createDecipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, iv);
let decrypted = decipher.update(encryptedText);
decrypted = Buffer.concat([decrypted, decipher.final()]);
Expand All @@ -60,10 +59,10 @@ function drill(o, callback) {
if (o && typeof o === "object") {
const copy = Array.isArray(o) ? [...o] : { ...o };
for (let k in copy) {
const res = drill(copy[k], callback)
const res = drill(copy[k], callback);
if (res) copy[k] = res;
else delete copy[k]
};
else delete copy[k];
}
return copy;
} else return callback(o);
}
Expand Down

0 comments on commit 37680c9

Please sign in to comment.