Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env node
- /**
- * encrypt / decrypt text by me
- * */
- var cryp = require('crypto-js');
- var comm = require('commander');
- comm
- .name('dync')
- .version('0.0.1', '--version')
- .option('-t, --text [text]', 'text yang akan di hash', 'text_default')
- .option('-s, --secret [secret]', 'nilai secret key yang akan digunakan', '123')
- .option('-e, --encrypt [encrypt]', 'untuk encrypt text ke hash')
- .option('-d, --decrypt [decrypt]', 'untuk decrypt hash ke text')
- comm.on('--help', () => {
- console.log('\n Example: \n\n');
- console.log(' $ node dync -e -t text_yang_akan_di_hash -s 123 ');
- console.log(' $ node dync -d -t hash_yang_akan_di_decr -s 123 ');
- })
- comm.parse(process.argv)
- var nilai_awal = [];
- var nilai_akhir = [];
- var text = new Array(comm.text) ;
- var tex2 = new Array(comm.secret);
- Array.prototype.push.apply(nilai_awal, text) ;
- Array.prototype.push.apply(nilai_akhir, tex2);
- if (comm.encrypt) {
- var hash = cryp.AES.encrypt(nilai_awal[0], nilai_akhir[0])
- console.log('\n Output Hash : ' + hash);
- console.log(' From Text : ' + nilai_awal[0]) ;
- console.log(' Tipe Hash : AES')
- console.log(' Secret Key : ' + nilai_akhir[0]);
- } else if (comm.decrypt) {
- var hash = cryp.AES.encrypt(nilai_awal[0], nilai_akhir[0]);
- var str1 = cryp.AES.decrypt(nilai_awal[0].toString(), nilai_akhir[0]);
- var str2 = str1.toString(cryp.enc.Utf8);
- console.log('\n Output Text : ' + str2);
- console.log(' From Hash : ' + nilai_awal[0]) ;
- console.log(' Tipe Hash : AES')
- console.log(' Secret Key : ' + nilai_akhir[0]);
- } else {
- comm.help()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement