Built motion from commit (unavailable).|2.5.20
[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 _0xf2ca=['final','end','close','unlink','decryptFile','algorithm','data','secret','utf8','base64','decryptString','createDecipher','crypto','bluebird','../../config/environment','session','aes-256-ctr','aes192','hasOwnProperty','encryptFile','createWriteStream','createCipher','update','binary','write'];(function(_0x21d744,_0x75c832){var _0x5693aa=function(_0x4d715d){while(--_0x4d715d){_0x21d744['push'](_0x21d744['shift']());}};_0x5693aa(++_0x75c832);}(_0xf2ca,0x16a));var _0xaf2c=function(_0x3c08ea,_0x419b25){_0x3c08ea=_0x3c08ea-0x0;var _0x4b6e51=_0xf2ca[_0x3c08ea];return _0x4b6e51;};'use strict';var crypto=require(_0xaf2c('0x0'));var fs=require('fs');var BPromise=require(_0xaf2c('0x1'));var config=require(_0xaf2c('0x2'));const stringOptions={'secret':config['secrets'][_0xaf2c('0x3')],'algorithm':_0xaf2c('0x4')};const fileOptions={'algorithm':_0xaf2c('0x5')};function combineOptions(_0x219511){var _0x3a724c={};for(var _0x10c910 in fileOptions){if(fileOptions['hasOwnProperty'](_0x10c910)){_0x3a724c[_0x10c910]=fileOptions[_0x10c910];}}if(_0x219511){for(var _0x1fd101 in _0x219511){if(_0x219511[_0xaf2c('0x6')](_0x1fd101)){_0x3a724c[_0x1fd101]=_0x219511[_0x1fd101];}}}return _0x3a724c;}exports[_0xaf2c('0x7')]=function(_0x1f9531,_0x58351f,_0x37fedd,_0x3c0421){return new BPromise(function(_0x4a7397,_0x2a011d){_0x3c0421=combineOptions(_0x3c0421);var _0x4ba0a2=new Buffer(_0x37fedd);var _0x439ca3=fs['createReadStream'](_0x1f9531);var _0x2f5099=fs[_0xaf2c('0x8')](_0x58351f);var _0x2e04e5=crypto[_0xaf2c('0x9')](_0x3c0421['algorithm'],_0x4ba0a2);_0x439ca3['on']('data',function(_0x2c0d88){var _0x41a5a0=new Buffer(_0x2e04e5[_0xaf2c('0xa')](_0x2c0d88),_0xaf2c('0xb'));_0x2f5099[_0xaf2c('0xc')](_0x41a5a0);});_0x439ca3['on']('end',function(){try{var _0x590126=new Buffer(_0x2e04e5[_0xaf2c('0xd')](_0xaf2c('0xb')),_0xaf2c('0xb'));_0x2f5099[_0xaf2c('0xc')](_0x590126);_0x2f5099[_0xaf2c('0xe')]();_0x2f5099['on'](_0xaf2c('0xf'),function(){return _0x4a7397(_0x58351f);});}catch(_0x214f47){fs[_0xaf2c('0x10')](_0x58351f);return _0x2a011d(_0x214f47);}});});};exports[_0xaf2c('0x11')]=function(_0x1d0633,_0x6ac8e,_0x2b4d13,_0x26bf7b){return new BPromise(function(_0x3432e4,_0x705d09){_0x26bf7b=combineOptions(_0x26bf7b);var _0x54c34a=new Buffer(_0x2b4d13);var _0x3ca650=fs['createReadStream'](_0x1d0633);var _0x278a28=fs[_0xaf2c('0x8')](_0x6ac8e);var _0x1d544a=crypto['createDecipher'](_0x26bf7b[_0xaf2c('0x12')],_0x54c34a);_0x3ca650['on'](_0xaf2c('0x13'),function(_0x1fec4c){var _0x20000b=new Buffer(_0x1d544a[_0xaf2c('0xa')](_0x1fec4c),_0xaf2c('0xb'));_0x278a28['write'](_0x20000b);});_0x3ca650['on'](_0xaf2c('0xe'),function(){try{var _0x164bcb=new Buffer(_0x1d544a[_0xaf2c('0xd')](_0xaf2c('0xb')),_0xaf2c('0xb'));_0x278a28['write'](_0x164bcb);_0x278a28[_0xaf2c('0xe')]();_0x278a28['on'](_0xaf2c('0xf'),function(){return _0x3432e4(_0x6ac8e);});}catch(_0x18153c){fs['unlink'](_0x6ac8e);return _0x705d09(_0x18153c);}});});};exports['encryptString']=function(_0x29cbdf,_0x303546,_0x1cafad){var _0x99f78d=_0x1cafad||stringOptions['algorithm'];var _0x2b8f1a=_0x303546||stringOptions[_0xaf2c('0x14')];var _0x3a0145=crypto[_0xaf2c('0x9')](_0x99f78d,_0x2b8f1a);var _0xe929b5=_0x3a0145[_0xaf2c('0xa')](_0x29cbdf,_0xaf2c('0x15'),'base64');_0xe929b5+=_0x3a0145[_0xaf2c('0xd')](_0xaf2c('0x16'));return _0xe929b5;};exports[_0xaf2c('0x17')]=function(_0x410536,_0x4b7cf2,_0x3fb190){var _0x589d47=_0x3fb190||stringOptions[_0xaf2c('0x12')];var _0x42f980=_0x4b7cf2||stringOptions[_0xaf2c('0x14')];var _0x5d685a=crypto[_0xaf2c('0x18')](_0x589d47,_0x42f980);var _0x2ea490=_0x5d685a[_0xaf2c('0xa')](_0x410536,'base64',_0xaf2c('0x15'));_0x2ea490+=_0x5d685a[_0xaf2c('0xd')](_0xaf2c('0x15'));return _0x2ea490;};