-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
161 lines (155 loc) · 3.73 KB
/
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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env node
const program = require('commander')
const inquirer = require('inquirer')
const scrypt = require('./simplecrypt.js')
program
.command('enc')
.alias('e')
.description('encrypt string with specified password')
.action(option => {
var strIn, pass;
option.parent.args.shift();
strIn = option.parent.args.shift();
const promptList = [{
type: 'password',
message: 'please enter password:',
name: 'pass',
default: "",
mask: true,
hidden:true
}];
inquirer.prompt(promptList).then(answers => {
pass = answers.pass;
let encStr = scrypt.encryptStr(strIn, pass);
if(encStr)
{
console.log("[OK]")
}
else
{
console.log("[ERR]")
}
console.log(encStr);
})
})
program
.command('dec')
.alias('d')
.description('decrypt string with specified password')
.action(option => {
var strToDecrypt, pass;
option.parent.args.shift();
strToDecrypt = option.parent.args.shift();
const promptList = [{
type: 'password',
message: 'please enter password:',
name: 'pass',
default: "",
mask: true,
hidden:true
}];
inquirer.prompt(promptList).then(answers => {
pass = answers.pass;
let decStr = scrypt.decryptStr(strToDecrypt, pass);
if(decStr)
{
console.log("[OK]")
}
else
{
console.log("[ERR]")
}
console.log(decStr);
})
})
program
.command('encfile')
.alias('ef')
.description('encrypt file with specified password')
.action(option => {
var fileToEncrypt, pass, fileToOutput;
option.parent.args.shift();
fileToEncrypt = option.parent.args.shift();
fileToOutput = option.parent.args.shift();
if(!fileToOutput ||fileToOutput.length == 0)
{
fileToOutput = fileToEncrypt + '.enc';
}
const confirmList = [{
type: 'confirm',
message: 'overwrite ' + fileToOutput +'?',
name: 'owFile',
default:true,
}];
inquirer.prompt(confirmList).then(answers => {
if(!answers.owFile)
return;
const promptList = [{
type: 'password',
message: 'please enter password:',
name: 'pass',
default: "",
mask: true,
hidden:true
}];
inquirer.prompt(promptList).then(answers => {
pass = answers.pass;
let encStr = scrypt.encryptFile(fileToEncrypt, pass, fileToOutput);
if(encStr)
{
console.log("[OK]")
}
else
{
console.log("[ERR]")
}
console.log(encStr);
})
})
})
program
.command('decfile')
.alias('df')
.description('decrypt file with specified password')
.action(option => {
var fileToDecrypt, pass, fileToOutput;
option.parent.args.shift();
fileToDecrypt = option.parent.args.shift();
fileToOutput = option.parent.args.shift();
if(!fileToOutput || fileToOutput.length == 0)
{
fileToOutput = fileToDecrypt + '.dec';
}
const confirmList = [{
type: 'confirm',
message: 'overwrite ' + fileToOutput + '?',
name: 'owFile',
default:true,
}];
inquirer.prompt(confirmList).then(answers => {
if(!answers.owFile)
return;
const promptList = [{
type: 'password',
message: 'please enter password:',
name: 'pass',
default: "",
mask: true,
hidden:true
}];
inquirer.prompt(promptList).then(answers => {
pass = answers.pass;
let decStr = scrypt.decryptFile(fileToDecrypt, pass, fileToOutput);
if(decStr)
{
console.log("[OK]")
}
else
{
console.log("[ERR]")
}
console.log(decStr);
})
})
})
program.parse(process.argv)