fscr 7.3.1 → 7.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import fcFilepicker from "fc-filepick";
|
|
3
3
|
import inquirer from "inquirer";
|
|
4
|
+
import fs from "fs";
|
|
4
5
|
import {decrypt, encrypt} from "../utils/encryption.js";
|
|
5
6
|
import {appendToFile, boxInform, ensureFile, readFile, readJson, writeFile} from "../utils/helpers.js";
|
|
6
7
|
import path from "path";
|
|
@@ -43,7 +44,7 @@ encrypted.encrypt = async (pass = null, encryptedFile = null, decryptedFile = nu
|
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
46
|
if (willEncrypt) {
|
|
46
|
-
|
|
47
|
+
const toEncrypt = fs.readFileSync(decryptedFile);
|
|
47
48
|
const ciphertext = encrypt(toEncrypt, pass);
|
|
48
49
|
await writeFile(encryptedFile, ciphertext.toString());
|
|
49
50
|
}
|
|
@@ -84,9 +85,9 @@ encrypted.decrypt = async (pass = null, encryptedFileLocation = null, decryptedF
|
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
if (willEncrypt) {
|
|
87
|
-
|
|
88
|
+
const toDecrypt = fs.readFileSync(encryptedFileLocation, "utf8");
|
|
88
89
|
const decryptedData = decrypt(toDecrypt, pass);
|
|
89
|
-
|
|
90
|
+
fs.writeFileSync(decryptedFileLocation, decryptedData);
|
|
90
91
|
console.warn(
|
|
91
92
|
`${chalk.bold.green.underline("DECRYPTED FILE:")} ${chalk.bold.dim(path.join(scriptsDir, decryptedFileLocation))}`
|
|
92
93
|
);
|
|
@@ -23,10 +23,8 @@ const encrypt = (toEncrypt, password) => {
|
|
|
23
23
|
const salt = crypto.randomBytes(8);
|
|
24
24
|
const { key, iv } = deriveKeyIv(password, salt);
|
|
25
25
|
const cipher = crypto.createCipheriv(algorithm, key, iv);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
cipher.final()
|
|
29
|
-
]);
|
|
26
|
+
const input = Buffer.isBuffer(toEncrypt) ? toEncrypt : Buffer.from(toEncrypt, "utf8");
|
|
27
|
+
const ciphertext = Buffer.concat([cipher.update(input), cipher.final()]);
|
|
30
28
|
return Buffer.concat([MAGIC, salt, ciphertext]).toString("base64");
|
|
31
29
|
};
|
|
32
30
|
|
|
@@ -34,9 +32,10 @@ const decryptLegacy = (toDecrypt, password) => {
|
|
|
34
32
|
const key = crypto.scryptSync(password, "salt", 24);
|
|
35
33
|
const iv = Buffer.alloc(16, 0);
|
|
36
34
|
const decipher = crypto.createDecipheriv("aes-192-cbc", key, iv);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
return Buffer.concat([
|
|
36
|
+
decipher.update(Buffer.from(String(toDecrypt).trim(), "hex")),
|
|
37
|
+
decipher.final()
|
|
38
|
+
]);
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
const decrypt = (toDecrypt, password) => {
|
|
@@ -51,7 +50,7 @@ const decrypt = (toDecrypt, password) => {
|
|
|
51
50
|
const { key, iv } = deriveKeyIv(password, salt);
|
|
52
51
|
const decipher = crypto.createDecipheriv(algorithm, key, iv);
|
|
53
52
|
try {
|
|
54
|
-
return Buffer.concat([decipher.update(ciphertext), decipher.final()])
|
|
53
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
55
54
|
} catch (e) {
|
|
56
55
|
throw new Error("Decryption failed — wrong password or corrupted file");
|
|
57
56
|
}
|