-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass.js
78 lines (65 loc) · 1.81 KB
/
pass.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*jshint esversion: 8 */
/*jshint node: true*/
// TODO: add qrcode-generator
// TODO: create html front-end
const sPass = require('./sPass');
const fs = require('fs');
const crypto = require('crypto'),
argv = require("yargs").argv,
resizedIV = Buffer.allocUnsafe(16),
iv = crypto
.createHash("sha256")
.update("myHashedIV")
.digest();
iv.copy(resizedIV);
// start sPass
var pass = new sPass.sPass();
if (argv.e && argv.key) {
const key = crypto
.createHash("sha256")
.update(argv.key)
.digest(),
cipher = crypto.createCipheriv("aes256", key, resizedIV),
msg = [];
site = '';
argv._.forEach( function (phrase) {
msg.push(cipher.update(phrase, "binary", "hex"));
site = phrase;
});
msg.push(cipher.final("hex"));
var enc = msg.join("");
if (argv.s) {
if (argv.user) {
pass.s(argv.user, enc, argv.key, site);
} else {
pass.s('doo', enc);
}
// file saved
}
} else if (argv.d && argv.key) {
const key = crypto
.createHash("sha256")
.update(argv.key)
.digest(),
decipher = crypto.createDecipheriv("aes256", key, resizedIV),
msg = [];
argv._.forEach( function (phrase) {
msg.push(decipher.update(phrase, "hex", "binary"));
});
msg.push(decipher.final("binary"));
console.log(msg.join(""));
} else if (argv.r) {
const key = crypto
.createHash("sha256")
.update(crypto.randomBytes(16))
.digest(),
cipher = crypto.createCipheriv("aes256", key, resizedIV),
msg = [];
argv._.forEach( function (phrase) {
msg.push(cipher.update(phrase, "binary", "hex"));
});
msg.push(cipher.final("hex"));
console.log(msg.join(""));
} else {
console.log('..');
}