Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Add support for passing password as a command line argument #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,28 @@ var fs = require("fs");
var prompt = require("prompt");
var path = require("path");

function runCrypto(fn, from, to, password, finished) {
from = fs.createReadStream(from);
to = fs.createWriteStream(to);
fn = fn("cast5-cbc", password);

from.pipe(fn).pipe(to);
from.on("end", function () {
console.log("done");
});
}

module.exports = function(fn) {
var from = path.join(process.cwd(), process.argv[2]);
var to = path.join(process.cwd(), process.argv[3]);
var password = process.argv[4];

if (password) {
runCrypto(fn, from, to, password);
return;
}

// Password isn't given in the command line, read it from prompt

prompt.start();

Expand All @@ -22,15 +41,9 @@ module.exports = function(fn) {
if (err) {
console.log(err);
} else {
from = fs.createReadStream(from);
to = fs.createWriteStream(to);
fn = fn("cast5-cbc", result.password);
prompt.stop();

from.pipe(fn).pipe(to);
from.on("end", function () {
console.log("done");
prompt.stop();
});
runCrypto(fn, from, to, result.password);
}
});
};