Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const id = require('nanoid')
- const read = require('read')
- const clipboardy = require('clipboardy')
- const crypt = require('crypto')
- const fs = require('fs')
- const algo = 'aes-256-ctr'
- read(
- { prompt: 'Master key: ', silent: true },
- (err, key) => {
- if (err) {
- throw err;
- return;
- }
- init(key);
- }
- )
- function init(key) {
- read(
- { prompt: 'Choose action: \n1. Generate\n2. Store to clipboard' },
- (err, output) => {
- if (output == '1') {
- generateNew(key)
- } else if (output == '2') {
- storeToClipboard(key)
- } else {
- init(key);
- }
- }
- )
- }
- function generateNew(key) {
- read(
- { prompt: 'Slave key name: ' },
- (err, name) => {
- let cipher = crypt.createCipher(algo, key),
- encrypted = cipher.update(
- id(24),
- 'utf8',
- 'hex'
- )
- encrypted += cipher.final('hex')
- // store to file
- fs.writeFileSync(
- __dirname + '/keys/' + md5(name),
- encrypted
- )
- }
- )
- }
- function storeToClipboard(key) {
- read(
- { prompt: 'Slave key name: ' },
- (err, name) => {
- let fc = fs.readFileSync(
- __dirname + '/keys/' + md5(name)
- ).toString()
- let decipher = crypt.createDecipher(algo, key)
- let crypted = decipher.update(
- fc, 'hex', 'utf8'
- )
- crypted += decipher.final('utf8')
- clipboardy.writeSync(crypted);
- }
- )
- }
- function md5(data) {
- return crypt.createHash('md5').update(data).digest("hex")
- }
Add Comment
Please, Sign In to add comment