Created
April 2, 2017 05:09
-
-
Save danielyaa5/c1c61701a38b4b2707487972217b22cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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