Built motion from commit f651e4b0a7312c0adceb5e57d6684a801a3aaf0d. Version 3.0.0...
[motion-next.git] / server / components / encryptor / index.js
1 const a825_0x44e7=['toString','close','aes-256-ctr','unlink','undefined','data','utf8','separator','createHash','app','alloc','slice','data1','read','secret','base64','end','exports','../../config/logger','parse','error','promises','key','aes192','sha256','split','join','some-naughty-secret','binary','open','from','length','Missing\x20Initialization\x20Vector\x20in\x20the\x20encrypted\x20string.\x20Using\x20fallbacks.','createReadStream','digest','createWriteStream','update','final','crypto','randomBytes','utf-8','substr','createCipheriv','you\x20must\x20pass\x20a\x20secret','license','algorithm','write'];(function(_0x3d2066,_0x44e77e){const _0x381eb7=function(_0x36589f){while(--_0x36589f){_0x3d2066['push'](_0x3d2066['shift']());}};_0x381eb7(++_0x44e77e);}(a825_0x44e7,0xc7));const a825_0x381e=function(_0x3d2066,_0x44e77e){_0x3d2066=_0x3d2066-0x0;let _0x381eb7=a825_0x44e7[_0x3d2066];return _0x381eb7;};const _0x2ad457=a825_0x381e;'use strict';const fs=require('fs'),crypto=require(_0x2ad457('0x1b')),{createCypherFallback}=require('./create-cypher-fallback'),logger=require(_0x2ad457('0x7'))(_0x2ad457('0x2d')),DEFAULT_STRING_OPTIONS={'secret':_0x2ad457('0x10'),'algorithm':_0x2ad457('0x26'),'separator':'!'},DEFAULT_FILE_OPTIONS={'algorithm':_0x2ad457('0xc'),'separator':'!'},KEYLEN_MAP={'aes-256-ctr':0x20,'aes192':0x18},IVLEN_MAP={'aes-256-ctr':0x18,'aes192':0x10};function getCipherAndIvText(_0x36589f,_0x3e4f25,_0x219e14){const _0x196c2f=_0x2ad457,_0x3f38c0=KEYLEN_MAP[_0x3e4f25],_0x498c13=crypto['createHash'](_0x196c2f('0xd'))['update'](String(_0x36589f))[_0x196c2f('0x17')](_0x196c2f('0x4'))[_0x196c2f('0x1e')](0x0,_0x3f38c0),_0x1910d6=Buffer[_0x196c2f('0x13')](_0x498c13,_0x196c2f('0x1d')),_0x26a88f=crypto[_0x196c2f('0x1c')](0x10),_0x2be530=_0x26a88f[_0x196c2f('0x24')]('base64'),_0x3875a3=crypto[_0x196c2f('0x1f')](_0x3e4f25,_0x1910d6,_0x26a88f,_0x219e14);return[_0x3875a3,_0x2be530];}function getDecipher(_0x451499,_0x21fb8b,_0x213e5a,_0x241777){const _0x1a46f0=_0x2ad457,_0x48ff5a=KEYLEN_MAP[_0x21fb8b],_0x5d618a=typeof _0x213e5a==='string'&&_0x213e5a[_0x1a46f0('0x14')]>0x0;let _0x512ef3=null,_0x58729d=null;if(!_0x5d618a){logger['info'](_0x1a46f0('0x15'));const _0x20a710=createCypherFallback(_0x21fb8b,_0x451499);_0x58729d=_0x20a710['iv'],_0x512ef3=_0x20a710[_0x1a46f0('0xb')];}const _0x328e03=_0x5d618a?Buffer[_0x1a46f0('0x13')](_0x213e5a,'base64'):_0x58729d,_0x12e074=_0x5d618a?crypto[_0x1a46f0('0x2c')](_0x1a46f0('0xd'))[_0x1a46f0('0x19')](String(_0x451499))['digest'](_0x1a46f0('0x4'))[_0x1a46f0('0x1e')](0x0,_0x48ff5a):null,_0x4ad9b1=_0x5d618a?Buffer[_0x1a46f0('0x13')](_0x12e074,_0x1a46f0('0x1d')):_0x512ef3,_0x5a795b=crypto['createDecipheriv'](_0x21fb8b,_0x4ad9b1,_0x328e03,_0x241777);return _0x5a795b;}function encryptFile(_0x2b7405,_0x2125ec,_0x4b0c08,_0x3a2322={}){return new Promise(function(_0x1da41b,_0x1575e8){const _0xea4d7a=a825_0x381e;_0x3a2322={...DEFAULT_FILE_OPTIONS,..._0x3a2322};const _0xaeb82d=fs[_0xea4d7a('0x16')](_0x2b7405),_0x54d8d8=fs[_0xea4d7a('0x18')](_0x2125ec),[_0x1a7fe2,_0x4210be]=getCipherAndIvText(_0x4b0c08,_0x3a2322[_0xea4d7a('0x22')]);_0xaeb82d['on'](_0xea4d7a('0x12'),function(){const _0x3fd4de=_0xea4d7a,_0x34d899=Buffer[_0x3fd4de('0x13')](_0x4210be,_0x3fd4de('0x4')),_0x2bbef8=Buffer[_0x3fd4de('0x13')](_0x3a2322[_0x3fd4de('0x2b')],_0x3fd4de('0x1d'));_0x54d8d8[_0x3fd4de('0x23')](Buffer['concat']([_0x34d899,_0x2bbef8],_0x34d899['length']+_0x2bbef8[_0x3fd4de('0x14')]));}),_0xaeb82d['on'](_0xea4d7a('0x29'),function(_0x56ee96){const _0x15c6cf=_0xea4d7a,_0x3f7c9d=Buffer[_0x15c6cf('0x13')](_0x1a7fe2[_0x15c6cf('0x19')](_0x56ee96),_0x15c6cf('0x11'));_0x54d8d8['write'](_0x3f7c9d);}),_0xaeb82d['on'](_0xea4d7a('0x5'),function(){const _0x38a2d1=_0xea4d7a;try{const _0x1bb01d=Buffer[_0x38a2d1('0x13')](_0x1a7fe2[_0x38a2d1('0x1a')](_0x38a2d1('0x11')),_0x38a2d1('0x11'));_0x54d8d8['write'](_0x1bb01d),_0x54d8d8[_0x38a2d1('0x5')](),_0x54d8d8['on']('close',function(){_0x1da41b(_0x2125ec);});}catch(_0x55557a){fs[_0x38a2d1('0x27')](_0x2125ec,_0x2775c3=>{_0x1575e8(_0x2775c3===null?_0x55557a:_0x2775c3);});}});});}async function decryptFile(_0x48bd44,_0x9f20d,_0x197b76,_0x1f7bca={}){const _0x2ad187=_0x2ad457;_0x1f7bca={...DEFAULT_FILE_OPTIONS,..._0x1f7bca};const _0x55b2b1=Buffer['from'](_0x1f7bca[_0x2ad187('0x2b')],_0x2ad187('0x1d'))[_0x2ad187('0x14')],_0x599305=IVLEN_MAP[_0x1f7bca['algorithm']],_0x4a6e2b=_0x599305+_0x55b2b1,_0xa4ec24=await fs[_0x2ad187('0xa')]['open'](_0x48bd44,'r'),_0x1b6049=Buffer[_0x2ad187('0x2e')](_0x4a6e2b),{buffer:_0x2e7b6d}=await _0xa4ec24[_0x2ad187('0x2')](_0x1b6049,0x0,_0x4a6e2b),_0x5305a4=_0x2e7b6d[_0x2ad187('0x0')](0x0,_0x599305),_0x1abf07=_0x2e7b6d[_0x2ad187('0x0')](_0x599305),_0x4fa7cd=_0x1abf07['toString'](_0x2ad187('0x1d')),_0x5eee30=_0x5305a4[_0x2ad187('0x24')]('base64'),_0x1a7cb6=_0x4fa7cd===_0x1f7bca['separator'];return new Promise(function(_0xd664f8,_0x25e865){const _0x6280bb=_0x2ad187,_0x95463e=fs['createReadStream'](_0x48bd44,{'start':_0x1a7cb6?_0x4a6e2b:0x0,'fd':_0xa4ec24,'autoClose':!![]}),_0x4ba2bf=fs[_0x6280bb('0x18')](_0x9f20d),_0x4fe89e=getDecipher(_0x197b76,_0x1f7bca['algorithm'],_0x1a7cb6?_0x5eee30:null);_0x95463e['on'](_0x6280bb('0x29'),function(_0x1c648c){const _0x452869=_0x6280bb,_0xa9f3a=Buffer['from'](_0x4fe89e['update'](_0x1c648c),'binary');_0x4ba2bf[_0x452869('0x23')](_0xa9f3a);}),_0x95463e['on'](_0x6280bb('0x9'),_0x3d3a48=>_0x25e865(_0x3d3a48)),_0x95463e['on'](_0x6280bb('0x5'),function(){const _0xb2eebd=_0x6280bb;try{const _0x5684ec=Buffer[_0xb2eebd('0x13')](_0x4fe89e[_0xb2eebd('0x1a')](_0xb2eebd('0x11')),'binary');_0x4ba2bf[_0xb2eebd('0x23')](_0x5684ec),_0x4ba2bf['end'](),_0x4ba2bf['on'](_0xb2eebd('0x25'),function(){_0xd664f8(_0x9f20d);});}catch(_0x58bd8d){fs[_0xb2eebd('0x27')](_0x9f20d,_0x5a05d7=>{_0x25e865(_0x5a05d7===null?_0x58bd8d:_0x5a05d7);});}});});}function encryptString(_0x300601,_0x13cc7f=DEFAULT_STRING_OPTIONS[_0x2ad457('0x3')],_0x497169=DEFAULT_STRING_OPTIONS[_0x2ad457('0x22')],_0x45d81b=DEFAULT_STRING_OPTIONS[_0x2ad457('0x2b')]){const _0x55ca03=_0x2ad457;if(!_0x300601||_0x300601[_0x55ca03('0x14')]===0x0)return _0x300601;if(!_0x13cc7f||_0x13cc7f[_0x55ca03('0x14')]===0x0)throw new Error(_0x55ca03('0x20'));const [_0x21b1d2,_0x55003b]=getCipherAndIvText(_0x13cc7f,_0x497169);let _0x394606=_0x21b1d2[_0x55ca03('0x19')](_0x300601,'utf8','base64');return _0x394606+=_0x21b1d2[_0x55ca03('0x1a')]('base64'),[_0x55003b,_0x394606][_0x55ca03('0xf')](_0x45d81b);}function decryptString(_0x5483d9,_0x272ce2=DEFAULT_STRING_OPTIONS['secret'],_0x42fcb7=DEFAULT_STRING_OPTIONS[_0x2ad457('0x22')],_0x1f7005=DEFAULT_STRING_OPTIONS[_0x2ad457('0x2b')]){const _0x1657b4=_0x2ad457;if(!_0x5483d9||_0x5483d9['length']===0x0)return _0x5483d9;if(!_0x272ce2||_0x272ce2['length']===0x0)throw new Error(_0x1657b4('0x20'));const _0x144b36=_0x5483d9[_0x1657b4('0xe')](_0x1f7005),_0x399262=_0x144b36[_0x1657b4('0x14')]===0x2,_0x3838ba=_0x399262?_0x144b36[0x1]:_0x5483d9,_0x5afdca=getDecipher(_0x272ce2,_0x42fcb7,_0x399262?_0x144b36[0x0]:undefined);let _0x11de45=_0x5afdca[_0x1657b4('0x19')](_0x3838ba,_0x1657b4('0x4'),_0x1657b4('0x2a'));return _0x11de45+=_0x5afdca[_0x1657b4('0x1a')](_0x1657b4('0x2a')),_0x11de45;}function getValueFromLicense(_0x4b292f,_0x21fca8){const _0x22a284=_0x2ad457;if(_0x4b292f&&_0x21fca8){if(_0x21fca8[_0x22a284('0x1')]&&_0x21fca8[_0x22a284('0x21')]){const _0x4912b0=_0x21fca8['data1'],_0x1916f2=_0x21fca8[_0x22a284('0x21')],_0x28f435=_0x4912b0[_0x22a284('0xe')]('-')[0x4],_0xcf6ca8=_0x4912b0[_0x22a284('0xe')]('-')[0x0],_0x18889b=[_0x28f435,_0x4912b0,_0xcf6ca8][_0x22a284('0xf')](':'),_0x49f6b9=getDecipher(_0x18889b,_0x22a284('0x26'));let _0x3aa747=_0x49f6b9[_0x22a284('0x19')](_0x1916f2,_0x22a284('0x4'),_0x22a284('0x2a'));_0x3aa747+=_0x49f6b9[_0x22a284('0x1a')](_0x22a284('0x2a'));const _0x293988=JSON[_0x22a284('0x8')](_0x3aa747);return typeof _0x293988[_0x4b292f]===_0x22a284('0x28')?null:_0x293988[_0x4b292f];}}return null;}module[_0x2ad457('0x6')]={'encryptFile':encryptFile,'decryptFile':decryptFile,'encryptString':encryptString,'decryptString':decryptString,'getValueFromLicense':getValueFromLicense};