Add controls algorithm (encrypt.js)
This commit is contained in:
parent
1d34fb7828
commit
34c192b0bc
4 changed files with 9 additions and 9 deletions
|
@ -27,7 +27,7 @@ currentValue = readlineSync.setPrompt([prompt])
|
||||||
|
|
||||||
Sets the prompt, for example when you run `node` on the command line, you see `> `, which is node's prompt.
|
Sets the prompt, for example when you run `node` on the command line, you see `> `, which is node's prompt.
|
||||||
`prompt` may be string, or may not be (e.g. number, Date, Object, etc.). This is converted to string (i.e. `toString` method is called) before it is displayed every time.
|
`prompt` may be string, or may not be (e.g. number, Date, Object, etc.). This is converted to string (i.e. `toString` method is called) before it is displayed every time.
|
||||||
For example: like bash `[foo-directory]# `
|
For example: `[foo-directory]# ` like bash
|
||||||
|
|
||||||
```js
|
```js
|
||||||
readlineSync.setPrompt({toString:
|
readlineSync.setPrompt({toString:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var algorithmCipher = 'aes-256-cbc',
|
var cipher = require('crypto').createCipher(
|
||||||
cipher = require('crypto').createCipher(algorithmCipher, process.argv[2]),
|
process.argv[2] /*algorithm*/, process.argv[3] /*password*/),
|
||||||
stdin = process.stdin,
|
stdin = process.stdin,
|
||||||
stdout = process.stdout,
|
stdout = process.stdout,
|
||||||
crypted = '';
|
crypted = '';
|
||||||
|
|
|
@ -95,14 +95,16 @@ function _readlineShell(noEchoBack) {
|
||||||
shellPath = 'cmd.exe';
|
shellPath = 'cmd.exe';
|
||||||
args = ['/V:ON', '/S', '/C',
|
args = ['/V:ON', '/S', '/C',
|
||||||
'%Q%' + __dirname + '\\read.bat%Q%' + optEchoBack +
|
'%Q%' + __dirname + '\\read.bat%Q%' + optEchoBack +
|
||||||
' |%Q%' + process.execPath + '%Q% %Q%' + __dirname + '\\encrypt.js%Q% %Q%' + password + '%Q%' +
|
' |%Q%' + process.execPath + '%Q% %Q%' + __dirname + '\\encrypt.js%Q%' +
|
||||||
|
' %Q%' + ALGORITHM_CIPHER + '%Q% %Q%' + password + '%Q%' +
|
||||||
' >%Q%' + pathStdout + '%Q%' +
|
' >%Q%' + pathStdout + '%Q%' +
|
||||||
' & (echo !ERRORLEVEL!)>%Q%' + pathStatus + '%Q% & (echo 1)>%Q%' + pathDone + '%Q%'];
|
' & (echo !ERRORLEVEL!)>%Q%' + pathStatus + '%Q% & (echo 1)>%Q%' + pathDone + '%Q%'];
|
||||||
} else {
|
} else {
|
||||||
shellPath = '/bin/sh';
|
shellPath = '/bin/sh';
|
||||||
args = ['-c',
|
args = ['-c',
|
||||||
'(' + shellPath + ' "' + __dirname + '/read.sh"' + optEchoBack + ')' +
|
'(' + shellPath + ' "' + __dirname + '/read.sh"' + optEchoBack + ')' +
|
||||||
' |"' + process.execPath + '" "' + __dirname + '/encrypt.js" "' + password + '"' +
|
' |"' + process.execPath + '" "' + __dirname + '/encrypt.js"' +
|
||||||
|
' "' + ALGORITHM_CIPHER + '" "' + password + '"' +
|
||||||
' >"' + pathStdout + '";' +
|
' >"' + pathStdout + '";' +
|
||||||
' echo $? >"' + pathStatus + '"; echo 1 >"' + pathDone + '"'];
|
' echo $? >"' + pathStatus + '"; echo 1 >"' + pathDone + '"'];
|
||||||
}
|
}
|
||||||
|
@ -110,9 +112,7 @@ function _readlineShell(noEchoBack) {
|
||||||
stdin.pause(); // re-start in child process
|
stdin.pause(); // re-start in child process
|
||||||
require('child_process').execFile(shellPath, args, {env: {Q: '"'}});
|
require('child_process').execFile(shellPath, args, {env: {Q: '"'}});
|
||||||
|
|
||||||
while (true) {
|
while (fs.readFileSync(pathDone, {encoding: encoding}).trim() !== '1') {}
|
||||||
if (fs.readFileSync(pathDone, {encoding: encoding}).trim() === '1') { break; }
|
|
||||||
}
|
|
||||||
if (fs.readFileSync(pathStatus, {encoding: encoding}).trim() === '0') {
|
if (fs.readFileSync(pathStatus, {encoding: encoding}).trim() === '0') {
|
||||||
shellStdout =
|
shellStdout =
|
||||||
decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) +
|
decipher.update(fs.readFileSync(pathStdout, {encoding: 'binary'}), 'hex', encoding) +
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "readline-sync",
|
"name": "readline-sync",
|
||||||
"description": "Synchronous Readline",
|
"description": "Synchronous Readline",
|
||||||
"version": "0.4.3",
|
"version": "0.4.4",
|
||||||
"homepage": "https://github.com/anseki/readline-sync",
|
"homepage": "https://github.com/anseki/readline-sync",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "anseki"
|
"name": "anseki"
|
||||||
|
|
Loading…
Reference in a new issue