Created
December 29, 2016 12:13
-
-
Save deptno/89085a99bbebcb8b9e21b8cb70b79c43 to your computer and use it in GitHub Desktop.
[cli] encrypt, decrypt via aes-256-ctr
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
#!/usr/bin/env node | |
const crypto = require('crypto'); | |
const alg = 'aes-256-ctr'; | |
const usage = _ => { | |
console.log('[usage]'); | |
['c', 'd'].map(opt => console.log(` ${exe} -${opt} secret payload`)); | |
process.exit(); | |
}; | |
const [_, exe, opt = '-h', secret, payload] = process.argv; | |
if (opt === '-h' || !opt.startsWith('-') || process.argv.length !== 5) { | |
usage(); | |
} else if (opt === '-c') { | |
const cipher = crypto.createCipher(alg, secret); | |
const crypted = cipher.update(payload, 'utf8', 'hex'); | |
console.log(crypted + cipher.final('hex')); | |
} else if (opt === '-d') { | |
const decipher = crypto.createDecipher(alg, secret); | |
const crypted = decipher.update(payload, 'hex', 'utf8'); | |
console.log(crypted + decipher.final('utf8')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment