Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. const crypto = require('crypto');
  2. const fs = require('fs');
  3. const args = process.argv.slice(2);
  4.  
  5. var credentials = { algorithm: "aes128", password: "594492b14a59184b6775f8b29a6cc73c" };
  6.  
  7. function encrypt(data) {
  8. var cipher = crypto.createCipher(credentials.algorithm, credentials.password);
  9. return cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
  10. }
  11.  
  12. function decrypt(data) {
  13. var cipher = crypto.createDecipher(credentials.algorithm, credentials.password);
  14. return cipher.update(data, 'hex', 'utf8') + cipher.final('utf8');
  15. }
  16.  
  17.  
  18. if(args[0]=="crypt"){
  19. fs.readFile(args[1], 'utf8', function(err, data) {
  20. if (err) throw err;
  21. fs.writeFile(args[2], encrypt(data), function(err) {
  22. if(err) {
  23. return console.log(err);
  24. }
  25. });
  26. });
  27. }else if(args[0]=="decrypt"){
  28. fs.readFile(args[1], 'utf8', function(err, data) {
  29. if (err) throw err;
  30. fs.writeFile(args[2], decrypt(data), function(err) {
  31. if(err) {
  32. return console.log(err);
  33. }
  34. });
  35. });
  36. }else{
  37. console.log("Usage: source dist");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement