com.fastchar.security.template.rsa_javascript Maven / Gradle / Ivy
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):factory(global.FastSecurity={})})(this,function(exports){"use strict";var navigator2={appName:"Netscape",userAgent:"Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1"};var window2={ASN1:null,Base64:null,Hex:null,crypto:null,href:null};try{window2=window;navigator2=navigator}catch(e){}var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz";function int2char(n){return BI_RM.charAt(n)}function op_and(x,y){return x&y}function op_or(x,y){return x|y}function op_xor(x,y){return x^y}function op_andnot(x,y){return x&~y}function lbit(x){if(x==0){return-1}var r=0;if((x&65535)==0){x>>=16;r+=16}if((x&255)==0){x>>=8;r+=8}if((x&15)==0){x>>=4;r+=4}if((x&3)==0){x>>=2;r+=2}if((x&1)==0){++r}return r}function cbit(x){var r=0;while(x!=0){x&=x-1;++r}return r}var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var b64pad="=";function hex2b64(h){var i;var c;var ret="";for(i=0;i+3<=h.length;i+=3){c=parseInt(h.substring(i,i+3),16);ret+=b64map.charAt(c>>6)+b64map.charAt(c&63)}if(i+1==h.length){c=parseInt(h.substring(i,i+1),16);ret+=b64map.charAt(c<<2)}else if(i+2==h.length){c=parseInt(h.substring(i,i+2),16);ret+=b64map.charAt(c>>2)+b64map.charAt((c&3)<<4)}while((ret.length&3)>0){ret+=b64pad}return ret}function b64tohex(s){var ret="";var i;var k=0;var slop=0;for(i=0;i>2);slop=v&3;k=1}else if(k==1){ret+=int2char(slop<<2|v>>4);slop=v&15;k=2}else if(k==2){ret+=int2char(slop);ret+=int2char(v>>2);slop=v&3;k=3}else{ret+=int2char(slop<<2|v>>4);ret+=int2char(v&15);k=0}}if(k==1){ret+=int2char(slop<<2)}return ret}var extendStatics=function(d,b){extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(d,b){d.__proto__=b}||function(d,b){for(var p in b)if(b.hasOwnProperty(p))d[p]=b[p]};return extendStatics(d,b)};function __extends(d,b){extendStatics(d,b);function __(){this.constructor=d}d.prototype=b===null?Object.create(b):(__.prototype=b.prototype,new __)}var decoder;var Hex={decode:function(a){var i;if(decoder===undefined){var hex="0123456789ABCDEF";var ignore=" \f\n\r\t \u2028\u2029";decoder={};for(i=0;i<16;++i){decoder[hex.charAt(i)]=i}hex=hex.toLowerCase();for(i=10;i<16;++i){decoder[hex.charAt(i)]=i}for(i=0;i=2){out[out.length]=bits;bits=0;char_count=0}else{bits<<=4}}if(char_count){throw new Error("Hex encoding incomplete: 4 bits missing")}return out}};var decoder$1;var Base64={decode:function(a){var i;if(decoder$1===undefined){var b64="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var ignore="= \f\n\r\t \u2028\u2029";decoder$1=Object.create(null);for(i=0;i<64;++i){decoder$1[b64.charAt(i)]=i}for(i=0;i=4){out[out.length]=bits>>16;out[out.length]=bits>>8&255;out[out.length]=bits&255;bits=0;char_count=0}else{bits<<=6}}switch(char_count){case 1:throw new Error("Base64 encoding incomplete: at least 2 bits missing");case 2:out[out.length]=bits>>10;break;case 3:out[out.length]=bits>>16;out[out.length]=bits>>8&255;break}return out},re:/-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,unarmor:function(a){var m=Base64.re.exec(a);if(m){if(m[1]){a=m[1]}else if(m[2]){a=m[2]}else{throw new Error("RegExp out of sync")}}return Base64.decode(a)}};var max=1e13;var Int10=function(){function Int10(value){this.buf=[+value||0]}Int10.prototype.mulAdd=function(m,c){var b=this.buf;var l=b.length;var i;var t;for(i=0;i0){b[i]=c}};Int10.prototype.sub=function(c){var b=this.buf;var l=b.length;var i;var t;for(i=0;i=0;--i){s+=(max+b[i]).toString().substring(1)}return s};Int10.prototype.valueOf=function(){var b=this.buf;var v=0;for(var i=b.length-1;i>=0;--i){v=v*max+b[i]}return v};Int10.prototype.simplify=function(){var b=this.buf;return b.length==1?b[0]:this};return Int10}();var ellipsis="…";var reTimeS=/^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;var reTimeL=/^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;function stringCut(str,len){if(str.length>len){str=str.substring(0,len)+ellipsis}return str}var Stream=function(){function Stream(enc,pos){this.hexDigits="0123456789ABCDEF";if(enc instanceof Stream){this.enc=enc.enc;this.pos=enc.pos}else{this.enc=enc;this.pos=pos}}Stream.prototype.get=function(pos){if(pos===undefined){pos=this.pos++}if(pos>=this.enc.length){throw new Error("Requesting byte offset "+pos+" on a stream of length "+this.enc.length)}return"string"===typeof this.enc?this.enc.charCodeAt(pos):this.enc[pos]};Stream.prototype.hexByte=function(b){return this.hexDigits.charAt(b>>4&15)+this.hexDigits.charAt(b&15)};Stream.prototype.hexDump=function(start,end,raw){var s="";for(var i=start;i176){return false}}return true};Stream.prototype.parseStringISO=function(start,end){var s="";for(var i=start;i191&&c<224){s+=String.fromCharCode((c&31)<<6|this.get(i++)&63)}else{s+=String.fromCharCode((c&15)<<12|(this.get(i++)&63)<<6|this.get(i++)&63)}}return s};Stream.prototype.parseStringBMP=function(start,end){var str="";var hi;var lo;for(var i=start;i127;var pad=neg?255:0;var len;var s="";while(v==pad&&++start4){s=v;len<<=3;while(((+s^pad)&128)==0){s=+s<<1;--len}s="("+len+" bit)\n"}if(neg){v=v-256}var n=new Int10(v);for(var i=start+1;i=skip;--j){s+=b>>j&1?"1":"0"}if(s.length>maxLength){return intro+stringCut(s,maxLength)}}return intro+s};Stream.prototype.parseOctetString=function(start,end,maxLength){if(this.isASCII(start,end)){return stringCut(this.parseStringISO(start,end),maxLength)}var len=end-start;var s="("+len+" byte)\n";maxLength/=2;if(len>maxLength){end=start+maxLength}for(var i=start;imaxLength){s+=ellipsis}return s};Stream.prototype.parseOID=function(start,end,maxLength){var s="";var n=new Int10;var bits=0;for(var i=start;imaxLength){return stringCut(s,maxLength)}n=new Int10;bits=0}}if(bits>0){s+=".incomplete"}return s};return Stream}();var ASN1=function(){function ASN1(stream,header,length,tag,sub){if(!(tag instanceof ASN1Tag)){throw new Error("Invalid tag value.")}this.stream=stream;this.header=header;this.length=length;this.tag=tag;this.sub=sub}ASN1.prototype.typeName=function(){switch(this.tag.tagClass){case 0:switch(this.tag.tagNumber){case 0:return"EOC";case 1:return"BOOLEAN";case 2:return"INTEGER";case 3:return"BIT_STRING";case 4:return"OCTET_STRING";case 5:return"NULL";case 6:return"OBJECT_IDENTIFIER";case 7:return"ObjectDescriptor";case 8:return"EXTERNAL";case 9:return"REAL";case 10:return"ENUMERATED";case 11:return"EMBEDDED_PDV";case 12:return"UTF8String";case 16:return"SEQUENCE";case 17:return"SET";case 18:return"NumericString";case 19:return"PrintableString";case 20:return"TeletexString";case 21:return"VideotexString";case 22:return"IA5String";case 23:return"UTCTime";case 24:return"GeneralizedTime";case 25:return"GraphicString";case 26:return"VisibleString";case 27:return"GeneralString";case 28:return"UniversalString";case 30:return"BMPString"}return"Universal_"+this.tag.tagNumber.toString();case 1:return"Application_"+this.tag.tagNumber.toString();case 2:return"["+this.tag.tagNumber.toString()+"]";case 3:return"Private_"+this.tag.tagNumber.toString()}};ASN1.prototype.content=function(maxLength){if(this.tag===undefined){return null}if(maxLength===undefined){maxLength=Infinity}var content=this.posContent();var len=Math.abs(this.length);if(!this.tag.isUniversal()){if(this.sub!==null){return"("+this.sub.length+" elem)"}return this.stream.parseOctetString(content,content+len,maxLength)}switch(this.tag.tagNumber){case 1:return this.stream.get(content)===0?"false":"true";case 2:return this.stream.parseInteger(content,content+len);case 3:return this.sub?"("+this.sub.length+" elem)":this.stream.parseBitString(content,content+len,maxLength);case 4:return this.sub?"("+this.sub.length+" elem)":this.stream.parseOctetString(content,content+len,maxLength);case 6:return this.stream.parseOID(content,content+len,maxLength);case 16:case 17:if(this.sub!==null){return"("+this.sub.length+" elem)"}else{return"(no elem)"}case 12:return stringCut(this.stream.parseStringUTF(content,content+len),maxLength);case 18:case 19:case 20:case 21:case 22:case 26:return stringCut(this.stream.parseStringISO(content,content+len),maxLength);case 30:return stringCut(this.stream.parseStringBMP(content,content+len),maxLength);case 23:case 24:return this.stream.parseTime(content,content+len,this.tag.tagNumber==23)}return null};ASN1.prototype.toString=function(){return this.typeName()+"@"+this.stream.pos+"[header:"+this.header+",length:"+this.length+",sub:"+(this.sub===null?"null":this.sub.length)+"]"};ASN1.prototype.toPrettyString=function(indent){if(indent===undefined){indent=""}var s=indent+this.typeName()+" @"+this.stream.pos;if(this.length>=0){s+="+"}s+=this.length;if(this.tag.tagConstructed){s+=" (constructed)"}else if(this.tag.isUniversal()&&(this.tag.tagNumber==3||this.tag.tagNumber==4)&&this.sub!==null){s+=" (encapsulates)"}s+="\n";if(this.sub!==null){indent+=" ";for(var i=0,max=this.sub.length;i6){throw new Error("Length over 48 bits not supported at position "+(stream.pos-1))}if(len===0){return null}buf=0;for(var i=0;i>6;this.tagConstructed=(buf&32)!==0;this.tagNumber=buf&31;if(this.tagNumber==31){var n=new Int10;do{buf=stream.get();n.mulAdd(128,buf&127)}while(buf&128);this.tagNumber=n.simplify()}}ASN1Tag.prototype.isUniversal=function(){return this.tagClass===0};ASN1Tag.prototype.isEOC=function(){return this.tagClass===0&&this.tagNumber===0};return ASN1Tag}();var dbits;var canary=0xdeadbeefcafe;var j_lm=(canary&16777215)==15715070;var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];var lplim=(1<<26)/lowprimes[lowprimes.length-1];var BigInteger=function(){function BigInteger(a,b,c){if(a!=null){if("number"==typeof a){this.fromNumber(a,b,c)}else if(b==null&&"string"!=typeof a){this.fromString(a,256)}else{this.fromString(a,b)}}}BigInteger.prototype.toString=function(b){if(this.s<0){return"-"+this.negate().toString(b)}var k;if(b==16){k=4}else if(b==8){k=3}else if(b==2){k=1}else if(b==32){k=5}else if(b==4){k=2}else{return this.toRadix(b)}var km=(1<0){if(p>p)>0){m=true;r=int2char(d)}while(i>=0){if(p>(p+=this.DB-k)}else{d=this[i]>>(p-=k)&km;if(p<=0){p+=this.DB;--i}}if(d>0){m=true}if(m){r+=int2char(d)}}}return m?r:"0"};BigInteger.prototype.negate=function(){var r=nbi();BigInteger.ZERO.subTo(this,r);return r};BigInteger.prototype.abs=function(){return this.s<0?this.negate():this};BigInteger.prototype.compareTo=function(a){var r=this.s-a.s;if(r!=0){return r}var i=this.t;r=i-a.t;if(r!=0){return this.s<0?-r:r}while(--i>=0){if((r=this[i]-a[i])!=0){return r}}return 0};BigInteger.prototype.bitLength=function(){if(this.t<=0){return 0}return this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)};BigInteger.prototype.mod=function(a){var r=nbi();this.abs().divRemTo(a,null,r);if(this.s<0&&r.compareTo(BigInteger.ZERO)>0){a.subTo(r,r)}return r};BigInteger.prototype.modPowInt=function(e,m){var z;if(e<256||m.isEven()){z=new Classic(m)}else{z=new Montgomery(m)}return this.exp(e,z)};BigInteger.prototype.clone=function(){var r=nbi();this.copyTo(r);return r};BigInteger.prototype.intValue=function(){if(this.s<0){if(this.t==1){return this[0]-this.DV}else if(this.t==0){return-1}}else if(this.t==1){return this[0]}else if(this.t==0){return 0}return(this[1]&(1<<32-this.DB)-1)<>24};BigInteger.prototype.shortValue=function(){return this.t==0?this.s:this[0]<<16>>16};BigInteger.prototype.signum=function(){if(this.s<0){return-1}else if(this.t<=0||this.t==1&&this[0]<=0){return 0}else{return 1}};BigInteger.prototype.toByteArray=function(){var i=this.t;var r=[];r[0]=this.s;var p=this.DB-i*this.DB%8;var d;var k=0;if(i-- >0){if(p>p)!=(this.s&this.DM)>>p){r[k++]=d|this.s<=0){if(p<8){d=(this[i]&(1<>(p+=this.DB-8)}else{d=this[i]>>(p-=8)&255;if(p<=0){p+=this.DB;--i}}if((d&128)!=0){d|=-256}if(k==0&&(this.s&128)!=(d&128)){++k}if(k>0||d!=this.s){r[k++]=d}}}return r};BigInteger.prototype.equals=function(a){return this.compareTo(a)==0};BigInteger.prototype.min=function(a){return this.compareTo(a)<0?this:a};BigInteger.prototype.max=function(a){return this.compareTo(a)>0?this:a};BigInteger.prototype.and=function(a){var r=nbi();this.bitwiseTo(a,op_and,r);return r};BigInteger.prototype.or=function(a){var r=nbi();this.bitwiseTo(a,op_or,r);return r};BigInteger.prototype.xor=function(a){var r=nbi();this.bitwiseTo(a,op_xor,r);return r};BigInteger.prototype.andNot=function(a){var r=nbi();this.bitwiseTo(a,op_andnot,r);return r};BigInteger.prototype.not=function(){var r=nbi();for(var i=0;i=this.t){return this.s!=0}return(this[j]&1<1){var g2=nbi();z.sqrTo(g[1],g2);while(n<=km){g[n]=nbi();z.mulTo(g2,g[n-2],g[n]);n+=2}}var j=e.t-1;var w;var is1=true;var r2=nbi();var t;i=nbits(e[j])-1;while(j>=0){if(i>=k1){w=e[j]>>i-k1&km}else{w=(e[j]&(1<0){w|=e[j-1]>>this.DB+i-k1}}n=k;while((w&1)==0){w>>=1;--n}if((i-=n)<0){i+=this.DB;--j}if(is1){g[w].copyTo(r);is1=false}else{while(n>1){z.sqrTo(r,r2);z.sqrTo(r2,r);n-=2}if(n>0){z.sqrTo(r,r2)}else{t=r;r=r2;r2=t}z.mulTo(r2,g[w],r)}while(j>=0&&(e[j]&1<=0){u.subTo(v,u);if(ac){a.subTo(c,a)}b.subTo(d,b)}else{v.subTo(u,v);if(ac){c.subTo(a,c)}d.subTo(b,d)}}if(v.compareTo(BigInteger.ONE)!=0){return BigInteger.ZERO}if(d.compareTo(m)>=0){return d.subtract(m)}if(d.signum()<0){d.addTo(m,d)}else{return d}if(d.signum()<0){return d.add(m)}else{return d}};BigInteger.prototype.pow=function(e){return this.exp(e,new NullExp)};BigInteger.prototype.gcd=function(a){var x=this.s<0?this.negate():this.clone();var y=a.s<0?a.negate():a.clone();if(x.compareTo(y)<0){var t=x;x=y;y=t}var i=x.getLowestSetBit();var g=y.getLowestSetBit();if(g<0){return x}if(i0){x.rShiftTo(g,x);y.rShiftTo(g,y)}while(x.signum()>0){if((i=x.getLowestSetBit())>0){x.rShiftTo(i,x)}if((i=y.getLowestSetBit())>0){y.rShiftTo(i,y)}if(x.compareTo(y)>=0){x.subTo(y,x);x.rShiftTo(1,x)}else{y.subTo(x,y);y.rShiftTo(1,y)}}if(g>0){y.lShiftTo(g,y)}return y};BigInteger.prototype.isProbablePrime=function(t){var i;var x=this.abs();if(x.t==1&&x[0]<=lowprimes[lowprimes.length-1]){for(i=0;i=0;--i){r[i]=this[i]}r.t=this.t;r.s=this.s};BigInteger.prototype.fromInt=function(x){this.t=1;this.s=x<0?-1:0;if(x>0){this[0]=x}else if(x<-1){this[0]=x+this.DV}else{this.t=0}};BigInteger.prototype.fromString=function(s,b){var k;if(b==16){k=4}else if(b==8){k=3}else if(b==256){k=8}else if(b==2){k=1}else if(b==32){k=5}else if(b==4){k=2}else{this.fromRadix(s,b);return}this.t=0;this.s=0;var i=s.length;var mi=false;var sh=0;while(--i>=0){var x=k==8?+s[i]&255:intAt(s,i);if(x<0){if(s.charAt(i)=="-"){mi=true}continue}mi=false;if(sh==0){this[this.t++]=x}else if(sh+k>this.DB){this[this.t-1]|=(x&(1<>this.DB-sh}else{this[this.t-1]|=x<=this.DB){sh-=this.DB}}if(k==8&&(+s[0]&128)!=0){this.s=-1;if(sh>0){this[this.t-1]|=(1<0&&this[this.t-1]==c){--this.t}};BigInteger.prototype.dlShiftTo=function(n,r){var i;for(i=this.t-1;i>=0;--i){r[i+n]=this[i]}for(i=n-1;i>=0;--i){r[i]=0}r.t=this.t+n;r.s=this.s};BigInteger.prototype.drShiftTo=function(n,r){for(var i=n;i=0;--i){r[i+ds+1]=this[i]>>cbs|c;c=(this[i]&bm)<=0;--i){r[i]=0}r[ds]=c;r.t=this.t+ds+1;r.s=this.s;r.clamp()};BigInteger.prototype.rShiftTo=function(n,r){r.s=this.s;var ds=Math.floor(n/this.DB);if(ds>=this.t){r.t=0;return}var bs=n%this.DB;var cbs=this.DB-bs;var bm=(1<>bs;for(var i=ds+1;i>bs}if(bs>0){r[this.t-ds-1]|=(this.s&bm)<>=this.DB}if(a.t>=this.DB}c+=this.s}else{c+=this.s;while(i>=this.DB}c-=a.s}r.s=c<0?-1:0;if(c<-1){r[i++]=this.DV+c}else if(c>0){r[i++]=c}r.t=i;r.clamp()};BigInteger.prototype.multiplyTo=function(a,r){var x=this.abs();var y=a.abs();var i=x.t;r.t=i+y.t;while(--i>=0){r[i]=0}for(i=0;i=0){r[i]=0}for(i=0;i=x.DV){r[i+x.t]-=x.DV;r[i+x.t+1]=1}}if(r.t>0){r[r.t-1]+=x.am(i,x[i],r,2*i,0,1)}r.s=0;r.clamp()};BigInteger.prototype.divRemTo=function(m,q,r){var pm=m.abs();if(pm.t<=0){return}var pt=this.abs();if(pt.t0){pm.lShiftTo(nsh,y);pt.lShiftTo(nsh,r)}else{pm.copyTo(y);pt.copyTo(r)}var ys=y.t;var y0=y[ys-1];if(y0==0){return}var yt=y0*(1<1?y[ys-2]>>this.F2:0);var d1=this.FV/yt;var d2=(1<=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t=0){var qd=r[--i]==y0?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))0){r.rShiftTo(nsh,r)}if(ts<0){BigInteger.ZERO.subTo(r,r)}};BigInteger.prototype.invDigit=function(){if(this.t<1){return 0}var x=this[0];if((x&1)==0){return 0}var y=x&3;y=y*(2-(x&15)*y)&15;y=y*(2-(x&255)*y)&255;y=y*(2-((x&65535)*y&65535))&65535;y=y*(2-x*y%this.DV)%this.DV;return y>0?this.DV-y:-y};BigInteger.prototype.isEven=function(){return(this.t>0?this[0]&1:this.s)==0};BigInteger.prototype.exp=function(e,z){if(e>4294967295||e<1){return BigInteger.ONE}var r=nbi();var r2=nbi();var g=z.convert(this);var i=nbits(e)-1;g.copyTo(r);while(--i>=0){z.sqrTo(r,r2);if((e&1<0){z.mulTo(r2,g,r)}else{var t=r;r=r2;r2=t}}return z.revert(r)};BigInteger.prototype.chunkSize=function(r){return Math.floor(Math.LN2*this.DB/Math.log(r))};BigInteger.prototype.toRadix=function(b){if(b==null){b=10}if(this.signum()==0||b<2||b>36){return"0"}var cs=this.chunkSize(b);var a=Math.pow(b,cs);var d=nbv(a);var y=nbi();var z=nbi();var r="";this.divRemTo(d,y,z);while(y.signum()>0){r=(a+z.intValue()).toString(b).substr(1)+r;y.divRemTo(d,y,z)}return z.intValue().toString(b)+r};BigInteger.prototype.fromRadix=function(s,b){this.fromInt(0);if(b==null){b=10}var cs=this.chunkSize(b);var d=Math.pow(b,cs);var mi=false;var j=0;var w=0;for(var i=0;i=cs){this.dMultiply(d);this.dAddOffset(w,0);j=0;w=0}}if(j>0){this.dMultiply(Math.pow(b,j));this.dAddOffset(w,0)}if(mi){BigInteger.ZERO.subTo(this,this)}};BigInteger.prototype.fromNumber=function(a,b,c){if("number"==typeof b){if(a<2){this.fromInt(1)}else{this.fromNumber(a,c);if(!this.testBit(a-1)){this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this)}if(this.isEven()){this.dAddOffset(1,0)}while(!this.isProbablePrime(b)){this.dAddOffset(2,0);if(this.bitLength()>a){this.subTo(BigInteger.ONE.shiftLeft(a-1),this)}}}}else{var x=[];var t=a&7;x.length=(a>>3)+1;b.nextBytes(x);if(t>0){x[0]&=(1<>=this.DB}if(a.t>=this.DB}c+=this.s}else{c+=this.s;while(i>=this.DB}c+=a.s}r.s=c<0?-1:0;if(c>0){r[i++]=c}else if(c<-1){r[i++]=this.DV+c}r.t=i;r.clamp()};BigInteger.prototype.dMultiply=function(n){this[this.t]=this.am(0,n-1,this,0,0,this.t);++this.t;this.clamp()};BigInteger.prototype.dAddOffset=function(n,w){if(n==0){return}while(this.t<=w){this[this.t++]=0}this[w]+=n;while(this[w]>=this.DV){this[w]-=this.DV;if(++w>=this.t){this[this.t++]=0}++this[w]}};BigInteger.prototype.multiplyLowerTo=function(a,n,r){var i=Math.min(this.t+a.t,n);r.s=0;r.t=i;while(i>0){r[--i]=0}for(var j=r.t-this.t;i=0){r[i]=0}for(i=Math.max(n-this.t,0);i0){if(d==0){r=this[0]%n}else{for(var i=this.t-1;i>=0;--i){r=(d*r+this[i])%n}}}return r};BigInteger.prototype.millerRabin=function(t){var n1=this.subtract(BigInteger.ONE);var k=n1.getLowestSetBit();if(k<=0){return false}var r=n1.shiftRight(k);t=t+1>>1;if(t>lowprimes.length){t=lowprimes.length}var a=nbi();for(var i=0;i0){x.rShiftTo(g,x);y.rShiftTo(g,y)}var gcda1=function(){if((i=x.getLowestSetBit())>0){x.rShiftTo(i,x)}if((i=y.getLowestSetBit())>0){y.rShiftTo(i,y)}if(x.compareTo(y)>=0){x.subTo(y,x);x.rShiftTo(1,x)}else{y.subTo(x,y);y.rShiftTo(1,y)}if(!(x.signum()>0)){if(g>0){y.lShiftTo(g,y)}setTimeout(function(){callback(y)},0)}else{setTimeout(gcda1,0)}};setTimeout(gcda1,10)};BigInteger.prototype.fromNumberAsync=function(a,b,c,callback){if("number"==typeof b){if(a<2){this.fromInt(1)}else{this.fromNumber(a,c);if(!this.testBit(a-1)){this.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,this)}if(this.isEven()){this.dAddOffset(1,0)}var bnp_1=this;var bnpfn1_1=function(){bnp_1.dAddOffset(2,0);if(bnp_1.bitLength()>a){bnp_1.subTo(BigInteger.ONE.shiftLeft(a-1),bnp_1)}if(bnp_1.isProbablePrime(b)){setTimeout(function(){callback()},0)}else{setTimeout(bnpfn1_1,0)}};setTimeout(bnpfn1_1,0)}}else{var x=[];var t=a&7;x.length=(a>>3)+1;b.nextBytes(x);if(t>0){x[0]&=(1<=0){return x.mod(this.m)}else{return x}};Classic.prototype.revert=function(x){return x};Classic.prototype.reduce=function(x){x.divRemTo(this.m,null,x)};Classic.prototype.mulTo=function(x,y,r){x.multiplyTo(y,r);this.reduce(r)};Classic.prototype.sqrTo=function(x,r){x.squareTo(r);this.reduce(r)};return Classic}();var Montgomery=function(){function Montgomery(m){this.m=m;this.mp=m.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<0){this.m.subTo(r,r)}return r};Montgomery.prototype.revert=function(x){var r=nbi();x.copyTo(r);this.reduce(r);return r};Montgomery.prototype.reduce=function(x){while(x.t<=this.mt2){x[x.t++]=0}for(var i=0;i>15)*this.mpl&this.um)<<15)&x.DM;j=i+this.m.t;x[j]+=this.m.am(0,u0,x,i,0,this.m.t);while(x[j]>=x.DV){x[j]-=x.DV;x[++j]++}}x.clamp();x.drShiftTo(this.m.t,x);if(x.compareTo(this.m)>=0){x.subTo(this.m,x)}};Montgomery.prototype.mulTo=function(x,y,r){x.multiplyTo(y,r);this.reduce(r)};Montgomery.prototype.sqrTo=function(x,r){x.squareTo(r);this.reduce(r)};return Montgomery}();var Barrett=function(){function Barrett(m){this.m=m;this.r2=nbi();this.q3=nbi();BigInteger.ONE.dlShiftTo(2*m.t,this.r2);this.mu=this.r2.divide(m)}Barrett.prototype.convert=function(x){if(x.s<0||x.t>2*this.m.t){return x.mod(this.m)}else if(x.compareTo(this.m)<0){return x}else{var r=nbi();x.copyTo(r);this.reduce(r);return r}};Barrett.prototype.revert=function(x){return x};Barrett.prototype.reduce=function(x){x.drShiftTo(this.m.t-1,this.r2);if(x.t>this.m.t+1){x.t=this.m.t+1;x.clamp()}this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3);this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);while(x.compareTo(this.r2)<0){x.dAddOffset(1,this.m.t+1)}x.subTo(this.r2,x);while(x.compareTo(this.m)>=0){x.subTo(this.m,x)}};Barrett.prototype.mulTo=function(x,y,r){x.multiplyTo(y,r);this.reduce(r)};Barrett.prototype.sqrTo=function(x,r){x.squareTo(r);this.reduce(r)};return Barrett}();function nbi(){return new BigInteger(null)}function parseBigInt(str,r){return new BigInteger(str,r)}function am1(i,x,w,j,c,n){while(--n>=0){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864);w[j++]=v&67108863}return c}function am2(i,x,w,j,c,n){var xl=x&32767;var xh=x>>15;while(--n>=0){var l=this[i]&32767;var h=this[i++]>>15;var m=xh*l+h*xl;l=xl*l+((m&32767)<<15)+w[j]+(c&1073741823);c=(l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++]=l&1073741823}return c}function am3(i,x,w,j,c,n){var xl=x&16383;var xh=x>>14;while(--n>=0){var l=this[i]&16383;var h=this[i++]>>14;var m=xh*l+h*xl;l=xl*l+((m&16383)<<14)+w[j]+c;c=(l>>28)+(m>>14)+xh*h;w[j++]=l&268435455}return c}if(j_lm&&navigator2.appName=="Microsoft Internet Explorer"){BigInteger.prototype.am=am2;dbits=30}else if(j_lm&&navigator2.appName!="Netscape"){BigInteger.prototype.am=am1;dbits=26}else{BigInteger.prototype.am=am3;dbits=28}BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<>>16)!=0){x=t;r+=16}if((t=x>>8)!=0){x=t;r+=8}if((t=x>>4)!=0){x=t;r+=4}if((t=x>>2)!=0){x=t;r+=2}if((t=x>>1)!=0){x=t;r+=1}return r}BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);var Arcfour=function(){function Arcfour(){this.i=0;this.j=0;this.S=[]}Arcfour.prototype.init=function(key){var i;var j;var t;for(i=0;i<256;++i){this.S[i]=i}j=0;for(i=0;i<256;++i){j=j+this.S[i]+key[i%key.length]&255;t=this.S[i];this.S[i]=this.S[j];this.S[j]=t}this.i=0;this.j=0};Arcfour.prototype.next=function(){var t;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;return this.S[t+this.S[this.i]&255]};return Arcfour}();function prng_newstate(){return new Arcfour}var rng_psize=256;var rng_state;var rng_pool=null;var rng_pptr;if(rng_pool==null){rng_pool=[];rng_pptr=0;var t=void 0;if(window2.crypto&&window2.crypto.getRandomValues){var z=new Uint32Array(256);window2.crypto.getRandomValues(z);for(t=0;t=256||rng_pptr>=rng_psize){if(window2.removeEventListener){window2.removeEventListener("mousemove",onMouseMoveListener_1,false)}else if(window2.detachEvent){window2.detachEvent("onmousemove",onMouseMoveListener_1)}return}try{var mouseCoordinates=ev.x+ev.y;rng_pool[rng_pptr++]=mouseCoordinates&255;this.count+=1}catch(e){}};if(window2.addEventListener){window2.addEventListener("mousemove",onMouseMoveListener_1,false)}else if(window2.attachEvent){window2.attachEvent("onmousemove",onMouseMoveListener_1)}}function rng_get_byte(){if(rng_state==null){rng_state=prng_newstate();while(rng_pptr=0&&n>0){var c=s.charCodeAt(i--);if(c<128){ba[--n]=c}else if(c>127&&c<2048){ba[--n]=c&63|128;ba[--n]=c>>6|192}else{ba[--n]=c&63|128;ba[--n]=c>>6&63|128;ba[--n]=c>>12|224}}ba[--n]=0;var rng=new SecureRandom;var x=[];while(n>2){x[0]=0;while(x[0]==0){rng.nextBytes(x)}ba[--n]=x[0]}ba[--n]=2;ba[--n]=0;return new BigInteger(ba)}var RSAKey=function(){function RSAKey(){this.n=null;this.e=0;this.d=null;this.p=null;this.q=null;this.dmp1=null;this.dmq1=null;this.coeff=null}RSAKey.prototype.doPublic=function(x){return x.modPowInt(this.e,this.n)};RSAKey.prototype.doPrivate=function(x){if(this.p==null||this.q==null){return x.modPow(this.d,this.n)}var xp=x.mod(this.p).modPow(this.dmp1,this.p);var xq=x.mod(this.q).modPow(this.dmq1,this.q);while(xp.compareTo(xq)<0){xp=xp.add(this.p)}return xp.subtract(xq).multiply(this.coeff).mod(this.p).multiply(this.q).add(xq)};RSAKey.prototype.setPublic=function(N,E){if(N!=null&&E!=null&&N.length>0&&E.length>0){this.n=parseBigInt(N,16);this.e=parseInt(E,16)}else{console.error("Invalid RSA public key")}};RSAKey.prototype.encrypt=function(text){var m=pkcs1pad2(text,this.n.bitLength()+7>>3);if(m==null){return null}var c=this.doPublic(m);if(c==null){return null}var h=c.toString(16);if((h.length&1)==0){return h}else{return"0"+h}};RSAKey.prototype.setPrivate=function(N,E,D){if(N!=null&&E!=null&&N.length>0&&E.length>0){this.n=parseBigInt(N,16);this.e=parseInt(E,16);this.d=parseBigInt(D,16)}else{console.error("Invalid RSA private key")}};RSAKey.prototype.setPrivateEx=function(N,E,D,P,Q,DP,DQ,C){if(N!=null&&E!=null&&N.length>0&&E.length>0){this.n=parseBigInt(N,16);this.e=parseInt(E,16);this.d=parseBigInt(D,16);this.p=parseBigInt(P,16);this.q=parseBigInt(Q,16);this.dmp1=parseBigInt(DP,16);this.dmq1=parseBigInt(DQ,16);this.coeff=parseBigInt(C,16)}else{console.error("Invalid RSA private key")}};RSAKey.prototype.generate=function(B,E){var rng=new SecureRandom;var qs=B>>1;this.e=parseInt(E,16);var ee=new BigInteger(E,16);for(;;){for(;;){this.p=new BigInteger(B-qs,1,rng);if(this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE)==0&&this.p.isProbablePrime(10)){break}}for(;;){this.q=new BigInteger(qs,1,rng);if(this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE)==0&&this.q.isProbablePrime(10)){break}}if(this.p.compareTo(this.q)<=0){var t=this.p;this.p=this.q;this.q=t}var p1=this.p.subtract(BigInteger.ONE);var q1=this.q.subtract(BigInteger.ONE);var phi=p1.multiply(q1);if(phi.gcd(ee).compareTo(BigInteger.ONE)==0){this.n=this.p.multiply(this.q);this.d=ee.modInverse(phi);this.dmp1=this.d.mod(p1);this.dmq1=this.d.mod(q1);this.coeff=this.q.modInverse(this.p);break}}};RSAKey.prototype.decrypt=function(ctext){var c=parseBigInt(ctext,16);var m=this.doPrivate(c);if(m==null){return null}return pkcs1unpad2(m,this.n.bitLength()+7>>3)};RSAKey.prototype.generateAsync=function(B,E,callback){var rng=new SecureRandom;var qs=B>>1;this.e=parseInt(E,16);var ee=new BigInteger(E,16);var rsa=this;var loop1=function(){var loop4=function(){if(rsa.p.compareTo(rsa.q)<=0){var t=rsa.p;rsa.p=rsa.q;rsa.q=t}var p1=rsa.p.subtract(BigInteger.ONE);var q1=rsa.q.subtract(BigInteger.ONE);var phi=p1.multiply(q1);if(phi.gcd(ee).compareTo(BigInteger.ONE)==0){rsa.n=rsa.p.multiply(rsa.q);rsa.d=ee.modInverse(phi);rsa.dmp1=rsa.d.mod(p1);rsa.dmq1=rsa.d.mod(q1);rsa.coeff=rsa.q.modInverse(rsa.p);setTimeout(function(){callback()},0)}else{setTimeout(loop1,0)}};var loop3=function(){rsa.q=nbi();rsa.q.fromNumberAsync(qs,1,rng,function(){rsa.q.subtract(BigInteger.ONE).gcda(ee,function(r){if(r.compareTo(BigInteger.ONE)==0&&rsa.q.isProbablePrime(10)){setTimeout(loop4,0)}else{setTimeout(loop3,0)}})})};var loop2=function(){rsa.p=nbi();rsa.p.fromNumberAsync(B-qs,1,rng,function(){rsa.p.subtract(BigInteger.ONE).gcda(ee,function(r){if(r.compareTo(BigInteger.ONE)==0&&rsa.p.isProbablePrime(10)){setTimeout(loop3,0)}else{setTimeout(loop2,0)}})})};setTimeout(loop2,0)};setTimeout(loop1,0)};RSAKey.prototype.sign=function(text,digestMethod,digestName){var header=getDigestHeader(digestName);var digest=header+digestMethod(text).toString();var m=pkcs1pad1(digest,this.n.bitLength()/4);if(m==null){return null}var c=this.doPrivate(m);if(c==null){return null}var h=c.toString(16);if((h.length&1)==0){return h}else{return"0"+h}};RSAKey.prototype.verify=function(text,signature,digestMethod){var c=parseBigInt(signature,16);var m=this.doPublic(c);if(m==null){return null}var unpadded=m.toString(16).replace(/^1f+00/,"");var digest=removeDigestHeader(unpadded);return digest==digestMethod(text).toString()};return RSAKey}();function pkcs1unpad2(d,n){var b=d.toByteArray();var i=0;while(i=b.length){return null}}var ret="";while(++i191&&c<224){ret+=String.fromCharCode((c&31)<<6|b[i+1]&63);++i}else{ret+=String.fromCharCode((c&15)<<12|(b[i+1]&63)<<6|b[i+2]&63);i+=2}}return ret}var DIGEST_HEADERS={md2:"3020300c06082a864886f70d020205000410",md5:"3020300c06082a864886f70d020505000410",sha1:"3021300906052b0e03021a05000414",sha224:"302d300d06096086480165030402040500041c",sha256:"3031300d060960864801650304020105000420",sha384:"3041300d060960864801650304020205000430",sha512:"3051300d060960864801650304020305000440",ripemd160:"3021300906052b2403020105000414"};function getDigestHeader(name){return DIGEST_HEADERS[name]||""}function removeDigestHeader(str){for(var name_1 in DIGEST_HEADERS){if(DIGEST_HEADERS.hasOwnProperty(name_1)){var header=DIGEST_HEADERS[name_1];var len=header.length;if(str.substr(0,len)==header){return str.substr(len)}}}return str}var YAHOO={};YAHOO.lang={extend:function(subc,superc,overrides){if(!superc||!subc){throw new Error("YAHOO.lang.extend failed, please check that "+"all dependencies are included.")}var F=function(){};F.prototype=superc.prototype;subc.prototype=new F;subc.prototype.constructor=subc;subc.superclass=superc.prototype;if(superc.prototype.constructor==Object.prototype.constructor){superc.prototype.constructor=superc}if(overrides){var i;for(i in overrides){subc.prototype[i]=overrides[i]}var _IEEnumFix=function(){},ADD=["toString","valueOf"];try{if(/MSIE/.test(navigator2.userAgent)){_IEEnumFix=function(r,s){for(i=0;i15){throw"ASN.1 length too long to represent by 8x: n = "+n.toString(16)}var head=128+hNlen;return head.toString(16)+hN}};this.getEncodedHex=function(){if(this.hTLV==null||this.isModified){this.hV=this.getFreshValueHex();this.hL=this.getLengthHexFromValue();this.hTLV=this.hT+this.hL+this.hV;this.isModified=false}return this.hTLV};this.getValueHex=function(){this.getEncodedHex();return this.hV};this.getFreshValueHex=function(){return""}};KJUR.asn1.DERAbstractString=function(params){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.getString=function(){return this.s};this.setString=function(newS){this.hTLV=null;this.isModified=true;this.s=newS;this.hV=stohex(this.s)};this.setStringHex=function(newHexString){this.hTLV=null;this.isModified=true;this.s=null;this.hV=newHexString};this.getFreshValueHex=function(){return this.hV};if(typeof params!="undefined"){if(typeof params=="string"){this.setString(params)}else if(typeof params["str"]!="undefined"){this.setString(params["str"])}else if(typeof params["hex"]!="undefined"){this.setStringHex(params["hex"])}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractString,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractTime=function(params){KJUR.asn1.DERAbstractTime.superclass.constructor.call(this);this.localDateToUTC=function(d){utc=d.getTime()+d.getTimezoneOffset()*6e4;var utcDate=new Date(utc);return utcDate};this.formatDate=function(dateObject,type,withMillis){var pad=this.zeroPadding;var d=this.localDateToUTC(dateObject);var year=String(d.getFullYear());if(type=="utc")year=year.substr(2,2);var month=pad(String(d.getMonth()+1),2);var day=pad(String(d.getDate()),2);var hour=pad(String(d.getHours()),2);var min=pad(String(d.getMinutes()),2);var sec=pad(String(d.getSeconds()),2);var s=year+month+day+hour+min+sec;if(withMillis===true){var millis=d.getMilliseconds();if(millis!=0){var sMillis=pad(String(millis),3);sMillis=sMillis.replace(/[0]+$/,"");s=s+"."+sMillis}}return s+"Z"};this.zeroPadding=function(s,len){if(s.length>=len)return s;return new Array(len-s.length+1).join("0")+s};this.getString=function(){return this.s};this.setString=function(newS){this.hTLV=null;this.isModified=true;this.s=newS;this.hV=stohex(newS)};this.setByDateValue=function(year,month,day,hour,min,sec){var dateObject=new Date(Date.UTC(year,month-1,day,hour,min,sec,0));this.setByDate(dateObject)};this.getFreshValueHex=function(){return this.hV}};YAHOO.lang.extend(KJUR.asn1.DERAbstractTime,KJUR.asn1.ASN1Object);KJUR.asn1.DERAbstractStructured=function(params){KJUR.asn1.DERAbstractString.superclass.constructor.call(this);this.setByASN1ObjectArray=function(asn1ObjectArray){this.hTLV=null;this.isModified=true;this.asn1Array=asn1ObjectArray};this.appendASN1Object=function(asn1Object){this.hTLV=null;this.isModified=true;this.asn1Array.push(asn1Object)};this.asn1Array=new Array;if(typeof params!="undefined"){if(typeof params["array"]!="undefined"){this.asn1Array=params["array"]}}};YAHOO.lang.extend(KJUR.asn1.DERAbstractStructured,KJUR.asn1.ASN1Object);KJUR.asn1.DERBoolean=function(){KJUR.asn1.DERBoolean.superclass.constructor.call(this);this.hT="01";this.hTLV="0101ff"};YAHOO.lang.extend(KJUR.asn1.DERBoolean,KJUR.asn1.ASN1Object);KJUR.asn1.DERInteger=function(params){KJUR.asn1.DERInteger.superclass.constructor.call(this);this.hT="02";this.setByBigInteger=function(bigIntegerValue){this.hTLV=null;this.isModified=true;this.hV=KJUR.asn1.ASN1Util.bigIntToMinTwosComplementsHex(bigIntegerValue)};this.setByInteger=function(intValue){var bi=new BigInteger(String(intValue),10);this.setByBigInteger(bi)};this.setValueHex=function(newHexString){this.hV=newHexString};this.getFreshValueHex=function(){return this.hV};if(typeof params!="undefined"){if(typeof params["bigint"]!="undefined"){this.setByBigInteger(params["bigint"])}else if(typeof params["int"]!="undefined"){this.setByInteger(params["int"])}else if(typeof params=="number"){this.setByInteger(params)}else if(typeof params["hex"]!="undefined"){this.setValueHex(params["hex"])}}};YAHOO.lang.extend(KJUR.asn1.DERInteger,KJUR.asn1.ASN1Object);KJUR.asn1.DERBitString=function(params){if(params!==undefined&&typeof params.obj!=="undefined"){var o=KJUR.asn1.ASN1Util.newObject(params.obj);params.hex="00"+o.getEncodedHex()}KJUR.asn1.DERBitString.superclass.constructor.call(this);this.hT="03";this.setHexValueIncludingUnusedBits=function(newHexStringIncludingUnusedBits){this.hTLV=null;this.isModified=true;this.hV=newHexStringIncludingUnusedBits};this.setUnusedBitsAndHexValue=function(unusedBits,hValue){if(unusedBits<0||7