-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1000 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const crypto = require("crypto");
const fs = require("fs");
const encryptor = require("file-encryptor");
function makeHash(buf) {
return crypto.createHash("sha256").update(buf, "utf8").digest("hex");
}
function makeHashFromFile(filepath) {
const buf = fs.readFileSync(filepath);
return makeHash(buf);
}
function encrypt(filepath, password, output) {
encryptor.encryptFile(filepath, output, password, (err) => {
if (err) {
console.error(err);
}
process.exit(0);
});
}
function decrypt(filepath, password, output) {
encryptor.decryptFile(filepath, output, password, (err) => {
if (err) {
console.error(err);
}
process.exit(0);
});
}
const mode = process.argv[2];
const filepath = process.argv[3];
const imgpath = process.argv[4];
const output = process.argv[5];
const password = makeHashFromFile(imgpath);
if (mode === "encrypt") {
encrypt(filepath, password, output);
} else if (mode === "decrypt") {
decrypt(filepath, password, output);
}