Advertisement
IbnuSyawall

AES | (enc/dec)

Jun 8th, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /usr/bin/env node
  2.  
  3. /**
  4.  * encrypt / decrypt text by me
  5.  * */
  6.  
  7. var cryp = require('crypto-js');
  8. var comm = require('commander');
  9.  
  10.  
  11. comm
  12.   .name('dync')
  13.   .version('0.0.1', '--version')
  14.   .option('-t, --text [text]', 'text yang akan di hash', 'text_default')
  15.   .option('-s, --secret [secret]', 'nilai secret key yang akan digunakan', '123')
  16.   .option('-e, --encrypt [encrypt]', 'untuk encrypt text ke hash')
  17.   .option('-d, --decrypt [decrypt]', 'untuk decrypt hash ke text')
  18.  
  19. comm.on('--help', () => {
  20.   console.log('\n  Example: \n\n');
  21.   console.log('   $ node dync -e -t text_yang_akan_di_hash -s 123 ');
  22.   console.log('   $ node dync -d -t hash_yang_akan_di_decr -s 123 ');
  23. })
  24.  
  25. comm.parse(process.argv)
  26.  
  27. var nilai_awal  = [];
  28. var nilai_akhir = [];
  29.  
  30. var text = new Array(comm.text)  ;
  31. var tex2 = new Array(comm.secret);
  32.  
  33. Array.prototype.push.apply(nilai_awal, text) ;
  34. Array.prototype.push.apply(nilai_akhir, tex2);
  35.  
  36. if (comm.encrypt) {
  37.  
  38.   var hash = cryp.AES.encrypt(nilai_awal[0], nilai_akhir[0])
  39.   console.log('\n Output Hash : ' + hash);
  40.   console.log(' From Text   : ' + nilai_awal[0]) ;
  41.   console.log(' Tipe Hash   : AES')
  42.   console.log(' Secret Key  : ' + nilai_akhir[0]);
  43.  
  44. } else if (comm.decrypt) {
  45.  
  46.   var hash = cryp.AES.encrypt(nilai_awal[0], nilai_akhir[0]);
  47.   var str1 = cryp.AES.decrypt(nilai_awal[0].toString(), nilai_akhir[0]);
  48.   var str2 = str1.toString(cryp.enc.Utf8);
  49.   console.log('\n Output Text : ' + str2);
  50.   console.log(' From Hash   : ' + nilai_awal[0]) ;
  51.   console.log(' Tipe Hash   : AES')
  52.   console.log(' Secret Key  : ' + nilai_akhir[0]);
  53.  
  54. } else {
  55.  
  56.   comm.help()
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement