From fa93dc1e0aeeee98dc2921a0b58865e19f72e9e9 Mon Sep 17 00:00:00 2001 From: Petr Balashov Date: Thu, 15 Jun 2017 19:15:23 +0200 Subject: [PATCH] added experimental encrypt/decrypt key shepherd api --- routes/shepherd.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/routes/shepherd.js b/routes/shepherd.js index f4e5daf..d3d394a 100644 --- a/routes/shepherd.js +++ b/routes/shepherd.js @@ -17,6 +17,7 @@ const electron = require('electron'), async = require('async'), rimraf = require('rimraf'), portscanner = require('portscanner'), + aes256 = require('nodejs-aes256'), Promise = require('bluebird'); const fixPath = require('fix-path'); @@ -137,6 +138,46 @@ shepherd.createIguanaDirs = function() { } } +shepherd.get('/encryptkey', function(req, res, next) { + if (req.query.ckey && + req.query.string) { + const encryptedKey = aes256.encrypt(req.query.ckey, req.query.string); + const successObj = { + 'msg': 'success', + 'result': encryptedKey + }; + + res.end(JSON.stringify(successObj)); + } else { + const errorObj = { + 'msg': 'error', + 'result': 'missing ckey or string to encrypt param' + }; + + res.end(JSON.stringify(errorObj)); + } +}); + +shepherd.get('/decryptkey', function(req, res, next) { + if (req.query.ckey && + req.query.string) { + const encryptedKey = aes256.decrypt(req.query.ckey, req.query.string); + const successObj = { + 'msg': 'success', + 'result': encryptedKey + }; + + res.end(JSON.stringify(successObj)); + } else { + const errorObj = { + 'msg': 'error', + 'result': 'missing ckey or string to encrypt param' + }; + + res.end(JSON.stringify(errorObj)); + } +}); + shepherd.get('/coinslist', function(req, res, next) { if (fs.existsSync(iguanaDir + '/shepherd/coinslist.json')) { fs.readFile(iguanaDir + '/shepherd/coinslist.json', 'utf8', function (err, data) {