659e9ed7b78f6cb3c2c5762849779773738492fe
[motion-next.git] / server / components / encryptor / index.js
1 const a825_0x32e5=['join','license','toString','secret','close','data1','from','Missing\x20Initialization\x20Vector\x20in\x20the\x20encrypted\x20string.\x20Using\x20fallbacks.','length','binary','createReadStream','some-naughty-secret','sha256','update','data','info','end','base64','createHash','exports','undefined','createWriteStream','final','open','app','write','promises','randomBytes','crypto','aes-256-ctr','digest','utf8','./create-cypher-fallback','you\x20must\x20pass\x20a\x20secret','slice','read','../../config/logger','algorithm','createCipheriv','substr','separator','split','utf-8','unlink'];(function(_0x2512d2,_0x32e51f){const _0x3492b8=function(_0x2134a7){while(--_0x2134a7){_0x2512d2['push'](_0x2512d2['shift']());}};_0x3492b8(++_0x32e51f);}(a825_0x32e5,0x107));const a825_0x3492=function(_0x2512d2,_0x32e51f){_0x2512d2=_0x2512d2-0x0;let _0x3492b8=a825_0x32e5[_0x2512d2];return _0x3492b8;};const _0x5b4f98=a825_0x3492;'use strict';const fs=require('fs'),crypto=require(_0x5b4f98('0x1d')),{createCypherFallback}=require(_0x5b4f98('0x21')),logger=require(_0x5b4f98('0x25'))(_0x5b4f98('0x19')),DEFAULT_STRING_OPTIONS={'secret':_0x5b4f98('0xc'),'algorithm':_0x5b4f98('0x1e'),'separator':'!'},DEFAULT_FILE_OPTIONS={'algorithm':'aes192','separator':'!'},KEYLEN_MAP={'aes-256-ctr':0x20,'aes192':0x18},IVLEN_MAP={'aes-256-ctr':0x18,'aes192':0x10};function getCipherAndIvText(_0x2134a7,_0x44fdb6,_0x3f8186){const _0x530c3e=_0x5b4f98,_0x1d21e9=KEYLEN_MAP[_0x44fdb6],_0x5e3b5e=crypto[_0x530c3e('0x13')](_0x530c3e('0xd'))[_0x530c3e('0xe')](String(_0x2134a7))['digest'](_0x530c3e('0x12'))[_0x530c3e('0x28')](0x0,_0x1d21e9),_0x3228e6=Buffer[_0x530c3e('0x7')](_0x5e3b5e,_0x530c3e('0x2b')),_0x58ebb3=crypto[_0x530c3e('0x1c')](0x10),_0x4c8e24=_0x58ebb3[_0x530c3e('0x3')](_0x530c3e('0x12')),_0x1d204c=crypto[_0x530c3e('0x27')](_0x44fdb6,_0x3228e6,_0x58ebb3,_0x3f8186);return[_0x1d204c,_0x4c8e24];}function getDecipher(_0x43dd20,_0x4c2482,_0x199299,_0x1bde75){const _0x5a230d=_0x5b4f98,_0x44fcb3=KEYLEN_MAP[_0x4c2482],_0x5055b9=typeof _0x199299==='string'&&_0x199299[_0x5a230d('0x9')]>0x0;let _0x44cf65=null,_0x5be345=null;if(!_0x5055b9){logger[_0x5a230d('0x10')](_0x5a230d('0x8'));const _0x2d462e=createCypherFallback(_0x4c2482,_0x43dd20);_0x5be345=_0x2d462e['iv'],_0x44cf65=_0x2d462e['key'];}const _0x29da05=_0x5055b9?Buffer[_0x5a230d('0x7')](_0x199299,'base64'):_0x5be345,_0x2c2dab=_0x5055b9?crypto[_0x5a230d('0x13')](_0x5a230d('0xd'))[_0x5a230d('0xe')](String(_0x43dd20))[_0x5a230d('0x1f')](_0x5a230d('0x12'))[_0x5a230d('0x28')](0x0,_0x44fcb3):null,_0x54f68c=_0x5055b9?Buffer[_0x5a230d('0x7')](_0x2c2dab,_0x5a230d('0x2b')):_0x44cf65,_0x1b3e7a=crypto['createDecipheriv'](_0x4c2482,_0x54f68c,_0x29da05,_0x1bde75);return _0x1b3e7a;}function encryptFile(_0x8e65eb,_0x11fe03,_0x578eed,_0x380633={}){return new Promise(function(_0x107a99,_0x46afbd){const _0x195f2e=a825_0x3492;_0x380633={...DEFAULT_FILE_OPTIONS,..._0x380633};const _0x421f32=fs['createReadStream'](_0x8e65eb),_0x12c1d8=fs['createWriteStream'](_0x11fe03),[_0x398bed,_0x49f952]=getCipherAndIvText(_0x578eed,_0x380633[_0x195f2e('0x26')]);_0x421f32['on'](_0x195f2e('0x18'),function(){const _0x15885a=_0x195f2e,_0x4f139d=Buffer['from'](_0x49f952,_0x15885a('0x12')),_0x16d97a=Buffer[_0x15885a('0x7')](_0x380633['separator'],_0x15885a('0x2b'));_0x12c1d8['write'](Buffer['concat']([_0x4f139d,_0x16d97a],_0x4f139d[_0x15885a('0x9')]+_0x16d97a[_0x15885a('0x9')]));}),_0x421f32['on'](_0x195f2e('0xf'),function(_0x2df21c){const _0x56b85f=_0x195f2e,_0x369c61=Buffer[_0x56b85f('0x7')](_0x398bed[_0x56b85f('0xe')](_0x2df21c),_0x56b85f('0xa'));_0x12c1d8[_0x56b85f('0x1a')](_0x369c61);}),_0x421f32['on'](_0x195f2e('0x11'),function(){const _0x9cc346=_0x195f2e;try{const _0x5235ad=Buffer[_0x9cc346('0x7')](_0x398bed['final']('binary'),'binary');_0x12c1d8[_0x9cc346('0x1a')](_0x5235ad),_0x12c1d8['end'](),_0x12c1d8['on'](_0x9cc346('0x5'),function(){_0x107a99(_0x11fe03);});}catch(_0x5ef62a){fs[_0x9cc346('0x0')](_0x11fe03,_0x37b539=>{_0x46afbd(_0x37b539===null?_0x5ef62a:_0x37b539);});}});});}async function decryptFile(_0x2dec68,_0x815482,_0x287761,_0x426abc={}){const _0x19a9e6=_0x5b4f98;_0x426abc={...DEFAULT_FILE_OPTIONS,..._0x426abc};const _0x7a312c=Buffer[_0x19a9e6('0x7')](_0x426abc['separator'],'utf-8')[_0x19a9e6('0x9')],_0x49b7b9=IVLEN_MAP[_0x426abc[_0x19a9e6('0x26')]],_0x433796=_0x49b7b9+_0x7a312c,_0x87b766=await fs[_0x19a9e6('0x1b')]['open'](_0x2dec68,'r'),_0x57716c=Buffer['alloc'](_0x433796),{buffer:_0x11c47d}=await _0x87b766[_0x19a9e6('0x24')](_0x57716c,0x0,_0x433796),_0x73122b=_0x11c47d[_0x19a9e6('0x23')](0x0,_0x49b7b9),_0x4facd8=_0x11c47d[_0x19a9e6('0x23')](_0x49b7b9),_0x4f3e42=_0x4facd8['toString']('utf-8'),_0x3c8d4a=_0x73122b[_0x19a9e6('0x3')]('base64'),_0x498f48=_0x4f3e42===_0x426abc[_0x19a9e6('0x29')];return new Promise(function(_0x2bf1c0,_0x248004){const _0x3d53b7=_0x19a9e6,_0x1f23f4=fs[_0x3d53b7('0xb')](_0x2dec68,{'start':_0x498f48?_0x433796:0x0,'fd':_0x87b766,'autoClose':!![]}),_0x3a5dce=fs[_0x3d53b7('0x16')](_0x815482),_0x387112=getDecipher(_0x287761,_0x426abc[_0x3d53b7('0x26')],_0x498f48?_0x3c8d4a:null);_0x1f23f4['on'](_0x3d53b7('0xf'),function(_0x58a14a){const _0x7a1595=_0x3d53b7,_0x315e14=Buffer['from'](_0x387112['update'](_0x58a14a),'binary');_0x3a5dce[_0x7a1595('0x1a')](_0x315e14);}),_0x1f23f4['on']('error',_0xad145e=>_0x248004(_0xad145e)),_0x1f23f4['on'](_0x3d53b7('0x11'),function(){const _0x427b67=_0x3d53b7;try{const _0x2726b0=Buffer[_0x427b67('0x7')](_0x387112['final'](_0x427b67('0xa')),_0x427b67('0xa'));_0x3a5dce[_0x427b67('0x1a')](_0x2726b0),_0x3a5dce[_0x427b67('0x11')](),_0x3a5dce['on']('close',function(){_0x2bf1c0(_0x815482);});}catch(_0x2ff90d){fs[_0x427b67('0x0')](_0x815482,_0x72c6cb=>{_0x248004(_0x72c6cb===null?_0x2ff90d:_0x72c6cb);});}});});}function encryptString(_0x39d26c,_0x77b488=DEFAULT_STRING_OPTIONS[_0x5b4f98('0x4')],_0x2e8ecd=DEFAULT_STRING_OPTIONS[_0x5b4f98('0x26')],_0x2df5c6=DEFAULT_STRING_OPTIONS[_0x5b4f98('0x29')]){const _0x52e2b2=_0x5b4f98;if(!_0x39d26c||_0x39d26c[_0x52e2b2('0x9')]===0x0)return _0x39d26c;if(!_0x77b488||_0x77b488[_0x52e2b2('0x9')]===0x0)throw new Error(_0x52e2b2('0x22'));const [_0x2cf0c9,_0x1d0d58]=getCipherAndIvText(_0x77b488,_0x2e8ecd);let _0x16c205=_0x2cf0c9[_0x52e2b2('0xe')](_0x39d26c,_0x52e2b2('0x20'),_0x52e2b2('0x12'));return _0x16c205+=_0x2cf0c9[_0x52e2b2('0x17')](_0x52e2b2('0x12')),[_0x1d0d58,_0x16c205][_0x52e2b2('0x1')](_0x2df5c6);}function decryptString(_0x269cb2,_0x375bd1=DEFAULT_STRING_OPTIONS['secret'],_0x566072=DEFAULT_STRING_OPTIONS['algorithm'],_0x1c64a5=DEFAULT_STRING_OPTIONS[_0x5b4f98('0x29')]){const _0x23d476=_0x5b4f98;if(!_0x269cb2||_0x269cb2[_0x23d476('0x9')]===0x0)return _0x269cb2;if(!_0x375bd1||_0x375bd1[_0x23d476('0x9')]===0x0)throw new Error(_0x23d476('0x22'));const _0x24e989=_0x269cb2[_0x23d476('0x2a')](_0x1c64a5),_0x68be12=_0x24e989['length']===0x2,_0x3ff30b=_0x68be12?_0x24e989[0x1]:_0x269cb2,_0x49b6d7=getDecipher(_0x375bd1,_0x566072,_0x68be12?_0x24e989[0x0]:undefined);let _0x42fe96=_0x49b6d7['update'](_0x3ff30b,_0x23d476('0x12'),_0x23d476('0x20'));return _0x42fe96+=_0x49b6d7[_0x23d476('0x17')](_0x23d476('0x20')),_0x42fe96;}function getValueFromLicense(_0x18df47,_0x5ab5da){const _0x1338e3=_0x5b4f98;if(_0x18df47&&_0x5ab5da){if(_0x5ab5da[_0x1338e3('0x6')]&&_0x5ab5da[_0x1338e3('0x2')]){const _0x3938f1=_0x5ab5da[_0x1338e3('0x6')],_0x2bf8e3=_0x5ab5da[_0x1338e3('0x2')],_0x28fd6b=_0x3938f1[_0x1338e3('0x2a')]('-')[0x4],_0x4950e9=_0x3938f1[_0x1338e3('0x2a')]('-')[0x0],_0x4a569b=[_0x28fd6b,_0x3938f1,_0x4950e9]['join'](':'),_0x267c08=getDecipher(_0x4a569b,_0x1338e3('0x1e'));let _0x3905d4=_0x267c08[_0x1338e3('0xe')](_0x2bf8e3,_0x1338e3('0x12'),_0x1338e3('0x20'));_0x3905d4+=_0x267c08[_0x1338e3('0x17')](_0x1338e3('0x20'));const _0x146e5a=JSON['parse'](_0x3905d4);return typeof _0x146e5a[_0x18df47]===_0x1338e3('0x15')?null:_0x146e5a[_0x18df47];}}return null;}module[_0x5b4f98('0x14')]={'encryptFile':encryptFile,'decryptFile':decryptFile,'encryptString':encryptString,'decryptString':decryptString,'getValueFromLicense':getValueFromLicense};