-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrsa-min.js
1 lines (1 loc) · 10.9 KB
/
rsa-min.js
1
!function(t){var i={};function r(o){if(i[o])return i[o].exports;var n=i[o]={i:o,l:!1,exports:{}};return t[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}r.m=t,r.c=i,r.d=function(t,i,o){r.o(t,i)||Object.defineProperty(t,i,{enumerable:!0,get:o})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,i){if(1&i&&(t=r(t)),8&i)return t;if(4&i&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&i&&"string"!=typeof t)for(var n in t)r.d(o,n,function(i){return t[i]}.bind(null,n));return o},r.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(i,"a",i),i},r.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},r.p="",r(r.s=0)}([function(t,i,r){t.exports=r(1)},function(t,i,r){"use strict";var o;r.r(i),r.d(i,"hex2b64",function(){return V}),r.d(i,"linebrk",function(){return j});function n(t,i,r){null!=t&&("number"==typeof t?this.fromNumber(t,i,r):null==i&&"string"!=typeof t?this.fromString(t,256):this.fromString(t,i))}function s(){return new n(null)}"Microsoft Internet Explorer"==navigator.appName?(n.prototype.am=function(t,i,r,o,n,s){for(var e=32767&i,h=i>>15;--s>=0;){var u=32767&this[t],f=this[t++]>>15,a=h*u+f*e;n=((u=e*u+((32767&a)<<15)+r[o]+(1073741823&n))>>>30)+(a>>>15)+h*f+(n>>>30),r[o++]=1073741823&u}return n},o=30):"Netscape"!=navigator.appName?(n.prototype.am=function(t,i,r,o,n,s){for(;--s>=0;){var e=i*this[t++]+r[o]+n;n=Math.floor(e/67108864),r[o++]=67108863&e}return n},o=26):(n.prototype.am=function(t,i,r,o,n,s){for(var e=16383&i,h=i>>14;--s>=0;){var u=16383&this[t],f=this[t++]>>14,a=h*u+f*e;n=((u=e*u+((16383&a)<<14)+r[o]+n)>>28)+(a>>14)+h*f,r[o++]=268435455&u}return n},o=28),n.prototype.DB=o,n.prototype.DM=(1<<o)-1,n.prototype.DV=1<<o;n.prototype.FV=Math.pow(2,52),n.prototype.F1=52-o,n.prototype.F2=2*o-52;var e,h,u="0123456789abcdefghijklmnopqrstuvwxyz",f=new Array;for(e="0".charCodeAt(0),h=0;h<=9;++h)f[e++]=h;for(e="a".charCodeAt(0),h=10;h<36;++h)f[e++]=h;for(e="A".charCodeAt(0),h=10;h<36;++h)f[e++]=h;function a(t){return u.charAt(t)}function p(t,i){var r=f[t.charCodeAt(i)];return null==r?-1:r}function l(t){var i=s();return i.fromInt(t),i}function c(t){var i,r=1;return 0!=(i=t>>>16)&&(t=i,r+=16),0!=(i=t>>8)&&(t=i,r+=8),0!=(i=t>>4)&&(t=i,r+=4),0!=(i=t>>2)&&(t=i,r+=2),0!=(i=t>>1)&&(t=i,r+=1),r}function m(t){this.m=t}function v(t){this.m=t,this.mp=t.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<t.DB-15)-1,this.mt2=2*t.t}function y(){this.i=0,this.j=0,this.S=new Array}m.prototype.convert=function(t){return t.s<0||t.compareTo(this.m)>=0?t.mod(this.m):t},m.prototype.revert=function(t){return t},m.prototype.reduce=function(t){t.divRemTo(this.m,null,t)},m.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},m.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},v.prototype.convert=function(t){var i=s();return t.abs().dlShiftTo(this.m.t,i),i.divRemTo(this.m,null,i),t.s<0&&i.compareTo(n.ZERO)>0&&this.m.subTo(i,i),i},v.prototype.revert=function(t){var i=s();return t.copyTo(i),this.reduce(i),i},v.prototype.reduce=function(t){for(;t.t<=this.mt2;)t[t.t++]=0;for(var i=0;i<this.m.t;++i){var r=32767&t[i],o=r*this.mpl+((r*this.mph+(t[i]>>15)*this.mpl&this.um)<<15)&t.DM;for(t[r=i+this.m.t]+=this.m.am(0,o,t,i,0,this.m.t);t[r]>=t.DV;)t[r]-=t.DV,t[++r]++}t.clamp(),t.drShiftTo(this.m.t,t),t.compareTo(this.m)>=0&&t.subTo(this.m,t)},v.prototype.mulTo=function(t,i,r){t.multiplyTo(i,r),this.reduce(r)},v.prototype.sqrTo=function(t,i){t.squareTo(i),this.reduce(i)},n.prototype.copyTo=function(t){for(var i=this.t-1;i>=0;--i)t[i]=this[i];t.t=this.t,t.s=this.s},n.prototype.fromInt=function(t){this.t=1,this.s=t<0?-1:0,t>0?this[0]=t:t<-1?this[0]=t+this.DV:this.t=0},n.prototype.fromString=function(t,i){var r;if(16==i)r=4;else if(8==i)r=3;else if(256==i)r=8;else if(2==i)r=1;else if(32==i)r=5;else{if(4!=i)return void this.fromRadix(t,i);r=2}this.t=0,this.s=0;for(var o=t.length,s=!1,e=0;--o>=0;){var h=8==r?255&t[o]:p(t,o);h<0?"-"==t.charAt(o)&&(s=!0):(s=!1,0==e?this[this.t++]=h:e+r>this.DB?(this[this.t-1]|=(h&(1<<this.DB-e)-1)<<e,this[this.t++]=h>>this.DB-e):this[this.t-1]|=h<<e,(e+=r)>=this.DB&&(e-=this.DB))}8==r&&0!=(128&t[0])&&(this.s=-1,e>0&&(this[this.t-1]|=(1<<this.DB-e)-1<<e)),this.clamp(),s&&n.ZERO.subTo(this,this)},n.prototype.clamp=function(){for(var t=this.s&this.DM;this.t>0&&this[this.t-1]==t;)--this.t},n.prototype.dlShiftTo=function(t,i){var r;for(r=this.t-1;r>=0;--r)i[r+t]=this[r];for(r=t-1;r>=0;--r)i[r]=0;i.t=this.t+t,i.s=this.s},n.prototype.drShiftTo=function(t,i){for(var r=t;r<this.t;++r)i[r-t]=this[r];i.t=Math.max(this.t-t,0),i.s=this.s},n.prototype.lShiftTo=function(t,i){var r,o=t%this.DB,n=this.DB-o,s=(1<<n)-1,e=Math.floor(t/this.DB),h=this.s<<o&this.DM;for(r=this.t-1;r>=0;--r)i[r+e+1]=this[r]>>n|h,h=(this[r]&s)<<o;for(r=e-1;r>=0;--r)i[r]=0;i[e]=h,i.t=this.t+e+1,i.s=this.s,i.clamp()},n.prototype.rShiftTo=function(t,i){i.s=this.s;var r=Math.floor(t/this.DB);if(r>=this.t)i.t=0;else{var o=t%this.DB,n=this.DB-o,s=(1<<o)-1;i[0]=this[r]>>o;for(var e=r+1;e<this.t;++e)i[e-r-1]|=(this[e]&s)<<n,i[e-r]=this[e]>>o;o>0&&(i[this.t-r-1]|=(this.s&s)<<n),i.t=this.t-r,i.clamp()}},n.prototype.subTo=function(t,i){for(var r=0,o=0,n=Math.min(t.t,this.t);r<n;)o+=this[r]-t[r],i[r++]=o&this.DM,o>>=this.DB;if(t.t<this.t){for(o-=t.s;r<this.t;)o+=this[r],i[r++]=o&this.DM,o>>=this.DB;o+=this.s}else{for(o+=this.s;r<t.t;)o-=t[r],i[r++]=o&this.DM,o>>=this.DB;o-=t.s}i.s=o<0?-1:0,o<-1?i[r++]=this.DV+o:o>0&&(i[r++]=o),i.t=r,i.clamp()},n.prototype.multiplyTo=function(t,i){var r=this.abs(),o=t.abs(),s=r.t;for(i.t=s+o.t;--s>=0;)i[s]=0;for(s=0;s<o.t;++s)i[s+r.t]=r.am(0,o[s],i,s,0,r.t);i.s=0,i.clamp(),this.s!=t.s&&n.ZERO.subTo(i,i)},n.prototype.squareTo=function(t){for(var i=this.abs(),r=t.t=2*i.t;--r>=0;)t[r]=0;for(r=0;r<i.t-1;++r){var o=i.am(r,i[r],t,2*r,0,1);(t[r+i.t]+=i.am(r+1,2*i[r],t,2*r+1,o,i.t-r-1))>=i.DV&&(t[r+i.t]-=i.DV,t[r+i.t+1]=1)}t.t>0&&(t[t.t-1]+=i.am(r,i[r],t,2*r,0,1)),t.s=0,t.clamp()},n.prototype.divRemTo=function(t,i,r){var o=t.abs();if(!(o.t<=0)){var e=this.abs();if(e.t<o.t)return null!=i&&i.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=s());var h=s(),u=this.s,f=t.s,a=this.DB-c(o[o.t-1]);a>0?(o.lShiftTo(a,h),e.lShiftTo(a,r)):(o.copyTo(h),e.copyTo(r));var p=h.t,l=h[p-1];if(0!=l){var m=l*(1<<this.F1)+(p>1?h[p-2]>>this.F2:0),v=this.FV/m,y=(1<<this.F1)/m,d=1<<this.F2,T=r.t,g=T-p,b=null==i?s():i;for(h.dlShiftTo(g,b),r.compareTo(b)>=0&&(r[r.t++]=1,r.subTo(b,r)),n.ONE.dlShiftTo(p,b),b.subTo(h,h);h.t<p;)h[h.t++]=0;for(;--g>=0;){var D=r[--T]==l?this.DM:Math.floor(r[T]*v+(r[T-1]+d)*y);if((r[T]+=h.am(0,D,r,g,0,p))<D)for(h.dlShiftTo(g,b),r.subTo(b,r);r[T]<--D;)r.subTo(b,r)}null!=i&&(r.drShiftTo(p,i),u!=f&&n.ZERO.subTo(i,i)),r.t=p,r.clamp(),a>0&&r.rShiftTo(a,r),u<0&&n.ZERO.subTo(r,r)}}},n.prototype.invDigit=function(){if(this.t<1)return 0;var t=this[0];if(0==(1&t))return 0;var i=3&t;return(i=(i=(i=(i=i*(2-(15&t)*i)&15)*(2-(255&t)*i)&255)*(2-((65535&t)*i&65535))&65535)*(2-t*i%this.DV)%this.DV)>0?this.DV-i:-i},n.prototype.isEven=function(){return 0==(this.t>0?1&this[0]:this.s)},n.prototype.exp=function(t,i){if(t>4294967295||t<1)return n.ONE;var r=s(),o=s(),e=i.convert(this),h=c(t)-1;for(e.copyTo(r);--h>=0;)if(i.sqrTo(r,o),(t&1<<h)>0)i.mulTo(o,e,r);else{var u=r;r=o,o=u}return i.revert(r)},n.prototype.toString=function(t){if(this.s<0)return"-"+this.negate().toString(t);var i;if(16==t)i=4;else if(8==t)i=3;else if(2==t)i=1;else if(32==t)i=5;else{if(4!=t)return this.toRadix(t);i=2}var r,o=(1<<i)-1,n=!1,s="",e=this.t,h=this.DB-e*this.DB%i;if(e-- >0)for(h<this.DB&&(r=this[e]>>h)>0&&(n=!0,s=a(r));e>=0;)h<i?(r=(this[e]&(1<<h)-1)<<i-h,r|=this[--e]>>(h+=this.DB-i)):(r=this[e]>>(h-=i)&o,h<=0&&(h+=this.DB,--e)),r>0&&(n=!0),n&&(s+=a(r));return n?s:"0"},n.prototype.negate=function(){var t=s();return n.ZERO.subTo(this,t),t},n.prototype.abs=function(){return this.s<0?this.negate():this},n.prototype.compareTo=function(t){var i=this.s-t.s;if(0!=i)return i;var r=this.t;if(0!=(i=r-t.t))return this.s<0?-i:i;for(;--r>=0;)if(0!=(i=this[r]-t[r]))return i;return 0},n.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+c(this[this.t-1]^this.s&this.DM)},n.prototype.mod=function(t){var i=s();return this.abs().divRemTo(t,null,i),this.s<0&&i.compareTo(n.ZERO)>0&&t.subTo(i,i),i},n.prototype.modPowInt=function(t,i){var r;return r=t<256||i.isEven()?new m(i):new v(i),this.exp(t,r)},n.ZERO=l(0),n.ONE=l(1),y.prototype.init=function(t){var i,r,o;for(i=0;i<256;++i)this.S[i]=i;for(r=0,i=0;i<256;++i)r=r+this.S[i]+t[i%t.length]&255,o=this.S[i],this.S[i]=this.S[r],this.S[r]=o;this.i=0,this.j=0},y.prototype.next=function(){var t;return this.i=this.i+1&255,this.j=this.j+this.S[this.i]&255,t=this.S[this.i],this.S[this.i]=this.S[this.j],this.S[this.j]=t,this.S[t+this.S[this.i]&255]};var d,T,g,b=256;function D(){var t;t=(new Date).getTime(),T[g++]^=255&t,T[g++]^=t>>8&255,T[g++]^=t>>16&255,T[g++]^=t>>24&255,g>=b&&(g-=b)}if(null==T){var S;if(T=new Array,g=0,window.crypto&&window.crypto.getRandomValues){var w=new Uint8Array(32);for(window.crypto.getRandomValues(w),S=0;S<32;++S)T[g++]=w[S]}if("Netscape"==navigator.appName&&navigator.appVersion<"5"&&window.crypto){var B=window.crypto.random(32);for(S=0;S<B.length;++S)T[g++]=255&B.charCodeAt(S)}for(;g<b;)S=Math.floor(65536*Math.random()),T[g++]=S>>>8,T[g++]=255&S;g=0,D()}function M(){if(null==d){for(D(),(d=new y).init(T),g=0;g<T.length;++g)T[g]=0;g=0}return d.next()}function A(){}function x(){this.n=null,this.e=0,this.d=null,this.p=null,this.q=null,this.dmp1=null,this.dmq1=null,this.coeff=null}A.prototype.nextBytes=function(t){var i;for(i=0;i<t.length;++i)t[i]=M()},x.prototype.doPublic=function(t){return t.modPowInt(this.e,this.n)},x.prototype.setPublic=function(t,i){null!=t&&null!=i&&t.length>0&&i.length>0?(this.n=new n(t,16),this.e=parseInt(i,16)):alert("Invalid RSA public key")},x.prototype.encrypt=function(t){var i=function(t,i){if(i<t.length+11)return alert("Message too long for RSA"),null;for(var r=new Array,o=t.length-1;o>=0&&i>0;){var s=t.charCodeAt(o--);s<128?r[--i]=s:s>127&&s<2048?(r[--i]=63&s|128,r[--i]=s>>6|192):(r[--i]=63&s|128,r[--i]=s>>6&63|128,r[--i]=s>>12|224)}r[--i]=0;for(var e=new A,h=new Array;i>2;){for(h[0]=0;0==h[0];)e.nextBytes(h);r[--i]=h[0]}return r[--i]=2,r[--i]=0,new n(r)}(t,this.n.bitLength()+7>>3);if(null==i)return null;var r=this.doPublic(i);if(null==r)return null;var o=r.toString(16);return 0==(1&o.length)?o:"0"+o};var O="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",R="=";function V(t){var i,r,o="";for(i=0;i+3<=t.length;i+=3)r=parseInt(t.substring(i,i+3),16),o+=O.charAt(r>>6)+O.charAt(63&r);for(i+1==t.length?(r=parseInt(t.substring(i,i+1),16),o+=O.charAt(r<<2)):i+2==t.length&&(r=parseInt(t.substring(i,i+2),16),o+=O.charAt(r>>2)+O.charAt((3&r)<<4));(3&o.length)>0;)o+=R;return o}function j(t,i){for(var r="",o=0;o+i<t.length;)r+=t.substring(o,o+i),o+=i;return r+t.substring(o,t.length)}i.default=x}]);