aes-decrypter.min.js 4.52 KB
/*! @name aes-decrypter @version 3.1.2 @license Apache-2.0 */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).aesDecrypter={})}(this,(function(t){"use strict";function e(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}var n=function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t},r=null,i=function(){function t(t){var e,n,i;r||(r=function(){var t,e,n,r,i,s,o,u,l=[[[],[],[],[],[]],[[],[],[],[],[]]],c=l[0],f=l[1],a=c[4],h=f[4],y=[],p=[];for(t=0;t<256;t++)p[(y[t]=t<<1^283*(t>>7))^t]=t;for(e=n=0;!a[e];e^=r||1,n=p[n]||1)for(s=(s=n^n<<1^n<<2^n<<3^n<<4)>>8^255&s^99,a[e]=s,h[s]=e,u=16843009*y[i=y[r=y[e]]]^65537*i^257*r^16843008*e,o=257*y[s]^16843008*s,t=0;t<4;t++)c[t][e]=o=o<<24^o>>>8,f[t][s]=u=u<<24^u>>>8;for(t=0;t<5;t++)c[t]=c[t].slice(0),f[t]=f[t].slice(0);return l}()),this._tables=[[r[0][0].slice(),r[0][1].slice(),r[0][2].slice(),r[0][3].slice(),r[0][4].slice()],[r[1][0].slice(),r[1][1].slice(),r[1][2].slice(),r[1][3].slice(),r[1][4].slice()]];var s=this._tables[0][4],o=this._tables[1],u=t.length,l=1;if(4!==u&&6!==u&&8!==u)throw new Error("Invalid aes key size");var c=t.slice(0),f=[];for(this._key=[c,f],e=u;e<4*u+28;e++)i=c[e-1],(e%u==0||8===u&&e%u==4)&&(i=s[i>>>24]<<24^s[i>>16&255]<<16^s[i>>8&255]<<8^s[255&i],e%u==0&&(i=i<<8^i>>>24^l<<24,l=l<<1^283*(l>>7))),c[e]=c[e-u]^i;for(n=0;e;n++,e--)i=c[3&n?e:e-4],f[n]=e<=4||n<4?i:o[0][s[i>>>24]]^o[1][s[i>>16&255]]^o[2][s[i>>8&255]]^o[3][s[255&i]]}return t.prototype.decrypt=function(t,e,n,r,i,s){var o,u,l,c,f=this._key[1],a=t^f[0],h=r^f[1],y=n^f[2],p=e^f[3],b=f.length/4-2,d=4,_=this._tables[1],v=_[0],g=_[1],m=_[2],w=_[3],A=_[4];for(c=0;c<b;c++)o=v[a>>>24]^g[h>>16&255]^m[y>>8&255]^w[255&p]^f[d],u=v[h>>>24]^g[y>>16&255]^m[p>>8&255]^w[255&a]^f[d+1],l=v[y>>>24]^g[p>>16&255]^m[a>>8&255]^w[255&h]^f[d+2],p=v[p>>>24]^g[a>>16&255]^m[h>>8&255]^w[255&y]^f[d+3],d+=4,a=o,h=u,y=l;for(c=0;c<4;c++)i[(3&-c)+s]=A[a>>>24]<<24^A[h>>16&255]<<16^A[y>>8&255]<<8^A[255&p]^f[d++],o=a,a=h,h=y,y=p,p=o},t}();var s=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e},o=function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var n=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(n,1),n>-1},e.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var n=e.length,r=0;r<n;++r)e[r].call(this,arguments[1]);else for(var i=Array.prototype.slice.call(arguments,1),s=e.length,o=0;o<s;++o)e[o].apply(this,i)},e.dispose=function(){this.listeners={}},e.pipe=function(t){this.on("data",(function(e){t.push(e)}))},t}(),u=function(t){function e(){var e;return(e=t.call(this,o)||this).jobs=[],e.delay=1,e.timeout_=null,e}s(e,t);var n=e.prototype;return n.processJob_=function(){this.jobs.shift()(),this.jobs.length?this.timeout_=setTimeout(this.processJob_.bind(this),this.delay):this.timeout_=null},n.push=function(t){this.jobs.push(t),this.timeout_||(this.timeout_=setTimeout(this.processJob_.bind(this),this.delay))},e}(o);var l=function(t){return t<<24|(65280&t)<<8|(16711680&t)>>8|t>>>24},c=function(t,e,n){var r,s,o,u,c,f,a,h,y,p=new Int32Array(t.buffer,t.byteOffset,t.byteLength>>2),b=new i(Array.prototype.slice.call(e)),d=new Uint8Array(t.byteLength),_=new Int32Array(d.buffer);for(r=n[0],s=n[1],o=n[2],u=n[3],y=0;y<p.length;y+=4)c=l(p[y]),f=l(p[y+1]),a=l(p[y+2]),h=l(p[y+3]),b.decrypt(c,f,a,h,_,y),_[y]=l(_[y]^r),_[y+1]=l(_[y+1]^s),_[y+2]=l(_[y+2]^o),_[y+3]=l(_[y+3]^u),r=c,s=f,o=a,u=h;return d},f=function(){function t(e,n,r,i){var s=t.STEP,o=new Int32Array(e.buffer),c=new Uint8Array(e.byteLength),f=0;for(this.asyncStream_=new u,this.asyncStream_.push(this.decryptChunk_(o.subarray(f,f+s),n,r,c)),f=s;f<o.length;f+=s)r=new Uint32Array([l(o[f-4]),l(o[f-3]),l(o[f-2]),l(o[f-1])]),this.asyncStream_.push(this.decryptChunk_(o.subarray(f,f+s),n,r,c));this.asyncStream_.push((function(){
/*! @name pkcs7 @version 1.0.4 @license Apache-2.0 */
var t;i(null,(t=c).subarray(0,t.byteLength-t[t.byteLength-1]))}))}return t.prototype.decryptChunk_=function(t,e,n,r){return function(){var i=c(t,e,n);r.set(i,t.byteOffset)}},n(t,null,[{key:"STEP",get:function(){return 32e3}}]),t}();t.AsyncStream=u,t.Decrypter=f,t.decrypt=c,Object.defineProperty(t,"__esModule",{value:!0})}));