Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const crypto = require('crypto');
- const fs = require('fs');
- const args = process.argv.slice(2);
- var credentials = { algorithm: "aes128", password: "594492b14a59184b6775f8b29a6cc73c" };
- function encrypt(data) {
- var cipher = crypto.createCipher(credentials.algorithm, credentials.password);
- return cipher.update(data, 'utf8', 'hex') + cipher.final('hex');
- }
- function decrypt(data) {
- var cipher = crypto.createDecipher(credentials.algorithm, credentials.password);
- return cipher.update(data, 'hex', 'utf8') + cipher.final('utf8');
- }
- if(args[0]=="crypt"){
- fs.readFile(args[1], 'utf8', function(err, data) {
- if (err) throw err;
- fs.writeFile(args[2], encrypt(data), function(err) {
- if(err) {
- return console.log(err);
- }
- });
- });
- }else if(args[0]=="decrypt"){
- fs.readFile(args[1], 'utf8', function(err, data) {
- if (err) throw err;
- fs.writeFile(args[2], decrypt(data), function(err) {
- if(err) {
- return console.log(err);
- }
- });
- });
- }else{
- console.log("Usage: source dist");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement