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 11, 2023
1 parent 37dac6c commit 7cde115
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/renderer/src/progress/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@ function encode(text) {
const cipher = crypto.createCipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, ENCRYPTION_IV);

const encrypted = cipher.update(text);
return `${CRYPTO_VERSION}:${ENCRYPTION_IV.toString("hex")}:${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) {
const [TEXT_CRYPTO_VERSION, ENCRYPTION_IV_HEX, encrypted] = text.split(":");

const [ TEXT_CRYPTO_VERSION, ENCRYPTION_IV_HEX, encrypted ] = text.split(":");

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 = encrypted.split(":");
let encryptedText = Buffer.from(textParts.join(":"), "hex");
let decipher = crypto.createDecipheriv(CRYPTO_ALGORITHM, ENCRYPTION_KEY, Buffer.from(ENCRYPTION_IV_HEX, 'hex'));
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();
Expand Down

0 comments on commit 7cde115

Please sign in to comment.