Skip to content
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
47 changes: 37 additions & 10 deletions src/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ const program = require('commander');

const encrypt = () => {
co(function *() {
let data = yield prompt(chalk.yellow('Enter data: '));
let password = yield prompt.password(chalk.yellow('Enter password: '));
let confirmPassword = yield prompt.password(chalk.yellow('Confirm password: '));
let data = program.data
if (!data) {
data = yield prompt(chalk.yellow('Enter data: '));
}

if (password !== confirmPassword) {
console.error(chalk.red('\nPasswords do not match. Please try again.'));
process.exit(1);
let password = program.password
if (!password) {
password = yield prompt.password(chalk.yellow('Enter password: '));
let confirmPassword = yield prompt.password(chalk.yellow('Confirm password: '));

if (password !== confirmPassword) {
console.error(chalk.red('\nPasswords do not match. Please try again.'));
process.exit(1);
}
}

const encryptedData = sjcl.encrypt(password, data);
Expand All @@ -26,14 +33,26 @@ const encrypt = () => {
console.error(chalk.red('\nThere we an error encrypting the data. Please try again'));
process.exit(1);
}
console.log(chalk.green('Encrypted data:\n\t\t %s'), encryptedData);

if (program.quite) {
console.log(encryptedData);
} else {
console.log(chalk.green('Encrypted data:\n\t\t %s'), encryptedData);
}
})
}

const decrypt = () => {
co(function *() {
let encryptedData = yield prompt(chalk.yellow('Enter encrypted data: '));
let password = yield prompt.password(chalk.yellow('Enter password: '));
let encryptedData = program.data
if (!encryptedData) {
encryptedData = yield prompt(chalk.yellow('Enter encrypted data: '));
}

let password = program.password
if (!password) {
password = yield prompt.password(chalk.yellow('Enter password: '));
}

let decryptedData;

Expand All @@ -44,10 +63,18 @@ const decrypt = () => {
process.exit(1);
}

console.log(chalk.green('Decrypted data:\n\t\t %s'), decryptedData);
if (program.quite) {
console.log(decryptedData)
} else {
console.log(chalk.green('Decrypted data:\n\t\t %s'), decryptedData);
}
})
}

program.option('-q, --quite', 'quiet (non-verbose) output')
program.option('-d, --data <data>', 'data to encrypt/decrypt')
program.option('-p, --password <password>', 'password to use for encryption/decryption')

program.command('encrypt')
.description('encrypt raw data')

Expand Down