Skip to content

Instantly share code, notes, and snippets.

@danielyaa5
Created April 2, 2017 05:09
Show Gist options
  • Select an option

  • Save danielyaa5/c1c61701a38b4b2707487972217b22cd to your computer and use it in GitHub Desktop.

Select an option

Save danielyaa5/c1c61701a38b4b2707487972217b22cd to your computer and use it in GitHub Desktop.
read({ prompt: 'Paste encrypted passwords file:'}, (err, encryptedText) => {
let decryptedText;
try {
decryptedText = decrypt(encryptedText, pwd);
} catch (e) {
return handleDecryptError(e);
} finally {
if (!decryptedText) return handleDecryptError();
}
read({ prompt: 'Enter "d" for decrypt, or enter "a" for append to a file:'}, (err, input) => {
if (err) return handleReadErr(err);
input = input.trim();
if (input === 'd') {
return console.log(decryptedText);
}
if (input === 'a') {
return read({ prompt: 'Enter new password data, use new line char for new lines:', silent: true }, (err, plaintextPwd) => {
if (err) return handleReadErr(err);
plaintextPwd = plaintextPwd.trim();
plaintextPwd = plaintextPwd.split('\\n').reduce((acc, item) => {
if(acc) acc += '\n';
acc += item;
return acc;
}, '');
const appendedPlainText = decryptedText + '\n' + plaintextPwd;
const appendedEncryptedText = encrypt(appendedPlainText, pwd);
console.log('New encrypted passwords:');
console.log(appendedEncryptedText);
})
}
return console.log('Please enter d or a.');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment