31ca2c6e6cc853888b74e704275158e02742c72a
[motion2.git] / server / components / encryptor / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x723e=['../../config/environment','secrets','session','aes-256-ctr','aes192','hasOwnProperty','encryptFile','createReadStream','createCipher','algorithm','update','binary','write','end','close','unlink','decryptFile','createWriteStream','createDecipher','data','encryptString','utf8','base64','final','decryptString','secret','bluebird'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x723e,0x179));var _0xe723=function(_0x52d238,_0x2c3a58){_0x52d238=_0x52d238-0x0;var _0x51520a=_0x723e[_0x52d238];return _0x51520a;};'use strict';var crypto=require('crypto');var fs=require('fs');var BPromise=require(_0xe723('0x0'));var config=require(_0xe723('0x1'));const stringOptions={'secret':config[_0xe723('0x2')][_0xe723('0x3')],'algorithm':_0xe723('0x4')};const fileOptions={'algorithm':_0xe723('0x5')};function combineOptions(_0x39e35c){var _0x1da20f={};for(var _0x8f78b2 in fileOptions){if(fileOptions[_0xe723('0x6')](_0x8f78b2)){_0x1da20f[_0x8f78b2]=fileOptions[_0x8f78b2];}}if(_0x39e35c){for(var _0x4b1c43 in _0x39e35c){if(_0x39e35c[_0xe723('0x6')](_0x4b1c43)){_0x1da20f[_0x4b1c43]=_0x39e35c[_0x4b1c43];}}}return _0x1da20f;}exports[_0xe723('0x7')]=function(_0x1335cd,_0x3bf082,_0x2aebbd,_0xe50f7){return new BPromise(function(_0x1b46e0,_0x1f07f3){_0xe50f7=combineOptions(_0xe50f7);var _0x4a6983=new Buffer(_0x2aebbd);var _0x380444=fs[_0xe723('0x8')](_0x1335cd);var _0x34831f=fs['createWriteStream'](_0x3bf082);var _0x24eef1=crypto[_0xe723('0x9')](_0xe50f7[_0xe723('0xa')],_0x4a6983);_0x380444['on']('data',function(_0x146098){var _0x3fddd4=new Buffer(_0x24eef1[_0xe723('0xb')](_0x146098),_0xe723('0xc'));_0x34831f[_0xe723('0xd')](_0x3fddd4);});_0x380444['on']('end',function(){try{var _0x29a1e=new Buffer(_0x24eef1['final']('binary'),'binary');_0x34831f['write'](_0x29a1e);_0x34831f[_0xe723('0xe')]();_0x34831f['on'](_0xe723('0xf'),function(){return _0x1b46e0(_0x3bf082);});}catch(_0x30ce1f){fs[_0xe723('0x10')](_0x3bf082);return _0x1f07f3(_0x30ce1f);}});});};exports[_0xe723('0x11')]=function(_0x5aec97,_0x23d0b2,_0xbf5ca3,_0xb8f1d){return new BPromise(function(_0x2ec702,_0x347fa0){_0xb8f1d=combineOptions(_0xb8f1d);var _0xa48053=new Buffer(_0xbf5ca3);var _0x2cd7ca=fs[_0xe723('0x8')](_0x5aec97);var _0x17e2c1=fs[_0xe723('0x12')](_0x23d0b2);var _0x2057d7=crypto[_0xe723('0x13')](_0xb8f1d[_0xe723('0xa')],_0xa48053);_0x2cd7ca['on'](_0xe723('0x14'),function(_0x5e8a90){var _0x5b2308=new Buffer(_0x2057d7[_0xe723('0xb')](_0x5e8a90),_0xe723('0xc'));_0x17e2c1['write'](_0x5b2308);});_0x2cd7ca['on'](_0xe723('0xe'),function(){try{var _0x2762e2=new Buffer(_0x2057d7['final'](_0xe723('0xc')),'binary');_0x17e2c1[_0xe723('0xd')](_0x2762e2);_0x17e2c1[_0xe723('0xe')]();_0x17e2c1['on'](_0xe723('0xf'),function(){return _0x2ec702(_0x23d0b2);});}catch(_0x1fe43d){fs[_0xe723('0x10')](_0x23d0b2);return _0x347fa0(_0x1fe43d);}});});};exports[_0xe723('0x15')]=function(_0x25f7d2,_0x15196c,_0x1228f2){var _0x19bd0c=_0x1228f2||stringOptions[_0xe723('0xa')];var _0x47dcf7=_0x15196c||stringOptions['secret'];var _0x384786=crypto['createCipher'](_0x19bd0c,_0x47dcf7);var _0xa258f3=_0x384786[_0xe723('0xb')](_0x25f7d2,_0xe723('0x16'),_0xe723('0x17'));_0xa258f3+=_0x384786[_0xe723('0x18')]('base64');return _0xa258f3;};exports[_0xe723('0x19')]=function(_0x52feb9,_0x52f919,_0x15911d){var _0x511c74=_0x15911d||stringOptions[_0xe723('0xa')];var _0x3a475a=_0x52f919||stringOptions[_0xe723('0x1a')];var _0x4d55cc=crypto[_0xe723('0x13')](_0x511c74,_0x3a475a);var _0x45e162=_0x4d55cc['update'](_0x52feb9,_0xe723('0x17'),'utf8');_0x45e162+=_0x4d55cc['final'](_0xe723('0x16'));return _0x45e162;};