﻿//-->
var System=System?System:{};System.Security=System.Security?System.Security:{};System.Security.Cryptography=System.Security.Cryptography?System.Security.Cryptography:{};System.Security.Cryptography.CryptographicException=function(message){this.name="System.Security.Cryptography.CryptographicException";this.message=message;this.toString=function(){return this.name+": "+this.message;}};System.Security.Cryptography.CryptographicException=function(message){this.name="System.Security.Cryptography.CryptographicException";this.message=message;this.toString=function(){return this.name+": "+this.message;}};System.Security.Cryptography.Rfc2898DeriveBytes=function(password,salt,iterations){this.IterationCount=1000;this.Password;this.Salt;this.Hmac;this.HmacLength=20;var _buffer;var _pos=0;var _f=0;this.F=function(s,c,i){var data=new Array(s.length+4);System.Buffer.BlockCopy(s,0,data,0,s.length);for(var b=0;b<4;b++)data[s.length+b]=0;var int4=System.BitConverter.GetBytes(i);System.Array.Reverse(int4,0,4);System.Buffer.BlockCopy(int4,0,data,s.length,4);var u1=this.Hmac.ComputeHash(this.Password,data);data=u1;for(var j=1;j<c;j++){var un=this.Hmac.ComputeHash(this.Password,data);for(var k=0;k<this.HmacLength;k++){u1[k]=(u1[k]^un[k])&0xff;}data=un;}return u1;};this.GetBytes=function(cb){var l=Math.floor(cb/this.HmacLength);var r=Math.floor(cb%this.HmacLength);if(r!=0)l++;var result=new Array(cb);var rpos=0;if(_pos>0){var count=Math.min(this.HmacLength-_pos,cb);System.Buffer.BlockCopy(_buffer,_pos,result,0,count);if(count>=cb)return result;_pos=0;rpos=(rpos+count)%cb;r=cb-rpos;}for(var i=1;i<=l;i++){_buffer=this.F(this.Salt,this.IterationCount,++_f);var count=((i==l)?r:this.HmacLength);System.Buffer.BlockCopy(_buffer,_pos,result,rpos,count);var bpos=rpos;rpos=(rpos+_pos+count)%cb;_pos=((count==this.HmacLength)?0:count);if((bpos+count)>=cb)return result;}return result;};function Reset(){_buffer=null;_pos=0;_f=0;};this.Initialize=function(){var password=arguments[0];var salt=arguments[1];var iterations=arguments[2];if(typeof(password)=="string")password=System.Text.Encoding.UTF8.GetBytes(password);if(typeof(salt)=="string")salt=System.Text.Encoding.UTF8.GetBytes(salt);this.Password=password;this.Salt=salt;if(iterations)this.IterationCount=iterations;this.Hmac=new System.Security.Cryptography.HMACSHA1();};this.Initialize.apply(this,arguments);};System.Security.Cryptography.ICryptoTransform=function(algorithm,encryption,rgbIV){var iv=new Array;var algo=null;var encrypt=false;var blockSizeByte=0;var temp=new Array;var temp2=new Array;var workBuff=new Array;var workout=new Array;var feedBackByte=0;var feedBackIter=0;var m_disposed=false;var lastBlock=false;var _rng;this.InputBlockSize=0;this.OutputBlockSize=0;this.CanTransformMultipleBlocks=true;this.CanReuseTransform=false;function Transform(input,output){switch(algo.Mode){case System.Security.Cryptography.CipherMode.ECB:ECB(input,output);break;case System.Security.Cryptography.CipherMode.CBC:CBC(input,output);break;case System.Security.Cryptography.CipherMode.CFB:CFB(input,output);break;case System.Security.Cryptography.CipherMode.OFB:OFB(input,output);break;case System.Security.Cryptography.CipherMode.CTS:CTS(input,output);break;default:var msg="Unkown CipherMode"+algo.Mode;throw msg;}};function ECB(input,output){if(encrypt){var outputBuffer=algo.Encrypt(algo.Key,input,System.Security.Cryptography.CipherMode.ECB);System.Buffer.BlockCopy(outputBuffer,0,output,0,blockSizeByte);}else{var outputBuffer=algo.Decrypt(algo.Key,input,System.Security.Cryptography.CipherMode.ECB);System.Buffer.BlockCopy(outputBuffer,0,output,0,blockSizeByte);}};function CBC(input,output){if(encrypt){for(var i=0;i<blockSizeByte;i++)temp[i]^=input[i];ECB(temp,output);System.Buffer.BlockCopy(output,0,temp,0,blockSizeByte);}else{System.Buffer.BlockCopy(input,0,temp2,0,blockSizeByte);ECB(input,output);for(var i=0;i<blockSizeByte;i++)output[i]^=temp[i];System.Buffer.BlockCopy(temp2,0,temp,0,blockSizeByte);}};function CFB(input,output){if(encrypt){for(var x=0;x<feedBackIter;x++){ECB(temp,temp2);for(var i=0;i<feedBackByte;i++){output[i+x]=(temp2[i]^input[i+x]);}System.Buffer.BlockCopy(temp,feedBackByte,temp,0,blockSizeByte-feedBackByte);System.Buffer.BlockCopy(output,x,temp,blockSizeByte-feedBackByte,feedBackByte);}}else{for(var x=0;x<feedBackIter;x++){encrypt=true;ECB(temp,temp2);encrypt=false;System.Buffer.BlockCopy(temp,feedBackByte,temp,0,blockSizeByte-feedBackByte);System.Buffer.BlockCopy(input,x,temp,blockSizeByte-feedBackByte,feedBackByte);for(var i=0;i<feedBackByte;i++){output[i+x]=(temp2[i]^input[i+x]);}}}};function OFB(input,utput){throw "OFB isn't supported";};function CTS(input,output){throw "CTS  isn't supported";};function CheckInput(inputBuffer,inputOffset,inputCount){if(!inputBuffer)throw "inputBuffer is can't be null";if(inputOffset<0)throw "inputOffset is out of range";if(inputCount<0)throw "inputCount is out of range";if(inputOffset>inputBuffer.length-inputCount){throw "inputBuffer is out of range (overflow)";}};this.TransformBlock=function(inputBuffer,inputOffset,inputCount,outputBuffer,outputOffset){if(m_disposed)throw new System.ObjectDisposedException("Object is disposed.");CheckInput(inputBuffer,inputOffset,inputCount);if(outputBuffer==null)throw new System.ArgumentNullException("outputBuffer");if(outputOffset<0)throw new System.ArgumentOutOfRangeException("outputOffset","< 0");if(outputOffset>outputBuffer.length-inputCount)throw new System.ArgumentException("outputBuffer","Overflow");return InternalTransformBlock(inputBuffer,inputOffset,inputCount,outputBuffer,outputOffset);};function KeepLastBlock(){return((!encrypt)&&(algo.Padding!=System.Security.Cryptography.PaddingMode.Zeros)&&(algo.Padding!=System.Security.Cryptography.PaddingMode.None));};function InternalTransformBlock(inputBuffer,inputOffset,inputCount,outputBuffer,outputOffset){var offs=inputOffset;var full=0;if(inputCount!=blockSizeByte){if((inputCount%blockSizeByte)!=0){throw new System.Security.Cryptography.CryptographicException("Invalid input block size.");}full=inputCount/blockSizeByte;}else{full=1;}if(KeepLastBlock())full--;var total=0;if(lastBlock){Transform(workBuff,workout);System.Buffer.BlockCopy(workout,0,outputBuffer,outputOffset,blockSizeByte);outputOffset+=blockSizeByte;total+=blockSizeByte;lastBlock=false;}for(var i=0;i<full;i++){System.Buffer.BlockCopy(inputBuffer,offs,workBuff,0,blockSizeByte);Transform(workBuff,workout);System.Buffer.BlockCopy(workout,0,outputBuffer,outputOffset,blockSizeByte);offs+=blockSizeByte;outputOffset+=blockSizeByte;total+=blockSizeByte;}if(KeepLastBlock()){System.Buffer.BlockCopy(inputBuffer,offs,workBuff,0,blockSizeByte);lastBlock=true;}return total;};function Random(buffer,start,length){if(_rng==null){_rng=new System.Security.Cryptography.RNGCryptoServiceProvider();}var random=new System.Byte(length);_rng.GetBytes(random);System.Buffer.BlockCopy(random,0,buffer,start,length);};function ThrowBadPaddingException(padding,length,position){var msg="Bad "+padding+" padding.";if(length>=0)msg+=" Invalid length "+length+".";if(position>=0)msg+=" Error found at position "+position+".";throw new System.Security.Cryptography.CryptographicException(msg);};function FinalEncrypt(inputBuffer,inputOffset,inputCount){var rem=blockSizeByte-inputCount;var blocksCount=1;var paddingSize=(rem>0)?rem:blockSizeByte;var paddedInput=new System.Byte(paddingSize);switch(algo.Padding){case System.Security.Cryptography.PaddingMode.None:if(rem!=0){throw new System.Security.Cryptography.CryptographicException("Invalid block length");}case System.Security.Cryptography.PaddingMode.Zeros:break;case System.Security.Cryptography.PaddingMode.ANSIX923:paddedInput[paddedInput.length-1]=paddingSize;if(rem==0)blocksCount=2;break;case System.Security.Cryptography.PaddingMode.ISO10126:Random(paddedInput,0,paddedInput.length-1);paddedInput[paddedInput.length-1]=paddingSize;if(rem==0)blocksCount=2;break;case System.Security.Cryptography.PaddingMode.PKCS7:for(var i=0;i<paddedInput.length;i++){paddedInput[i]=paddingSize;}if(rem==0)blocksCount=2;break;default:break;}var iBuffer=new System.Byte(blockSizeByte*blocksCount);var oBuffer=new System.Byte(blockSizeByte*blocksCount);System.Buffer.BlockCopy(inputBuffer,inputOffset,iBuffer,0,inputCount);if((rem>0)||(rem==0&&blocksCount==2)){System.Buffer.BlockCopy(paddedInput,0,iBuffer,inputCount,paddingSize);}for(var i=0;i<blocksCount;i++){var offset=i*blockSizeByte;InternalTransformBlock(iBuffer,offset,blockSizeByte,oBuffer,offset);}return oBuffer;};function FinalDecrypt(inputBuffer,inputOffset,inputCount){if((inputCount%blockSizeByte)>0){throw new System.Security.Cryptography.CryptographicException("Invalid input block size.");}var total=inputCount;if(lastBlock)total+=blockSizeByte;var res=new System.Byte(total);var outputOffset=0;while(inputCount>0){var len=InternalTransformBlock(inputBuffer,inputOffset,blockSizeByte,res,outputOffset);inputOffset+=blockSizeByte;outputOffset+=len;inputCount-=blockSizeByte;}if(lastBlock){Transform(workBuff,workout);System.Buffer.BlockCopy(workout,0,res,outputOffset,blockSizeByte);outputOffset+=blockSizeByte;lastBlock=false;}var padding=((total>0)?res[total-1]:0);switch(algo.Padding){case System.Security.Cryptography.PaddingMode.ANSIX923:if((padding==0)||(padding>blockSizeByte)){System.Security.Cryptography.ThrowBadPaddingException(algo.Padding,padding,-1);}for(var i=padding;i>0;i--){if(res[total-1-i]!=0x00)System.Security.Cryptography.ThrowBadPaddingException(algo.Padding,-1,i);}total-=padding;break;case System.Security.Cryptography.PaddingMode.ISO10126:if((padding==0)||(padding>blockSizeByte))System.Security.Cryptography.ThrowBadPaddingException(algo.Padding,padding,-1);total-=padding;break;case System.Security.Cryptography.PaddingMode.PKCS7:if((padding==0)||(padding>blockSizeByte)){Trace.Write(padding+", "+blockSizeByte);System.Security.Cryptography.ThrowBadPaddingException(algo.Padding,padding,-1);}for(var i=padding-1;i>0;i--){if(res[total-1-i]!=padding){System.Security.Cryptography.ThrowBadPaddingException(algo.Padding,-1,i);}}total-=padding;break;case System.Security.Cryptography.PaddingMode.None:case System.Security.Cryptography.PaddingMode.Zeros:break;}if(total>0){var data=new System.Byte(total);System.Buffer.BlockCopy(res,0,data,0,total);System.Array.Clear(res,0,res.length);return data;}else{return new System.Byte(0);}};this.TransformFinalBlock=function(inputBuffer,inputOffset,inputCount){if(m_disposed)throw new ObjectDisposedException("Object is disposed");CheckInput(inputBuffer,inputOffset,inputCount);if(encrypt){return FinalEncrypt(inputBuffer,inputOffset,inputCount);}else{return FinalDecrypt(inputBuffer,inputOffset,inputCount);}};this.Initialize=function(algorithm,encryption){algo=algorithm;encrypt=encryption;blockSizeByte=(algo.BlockSize>>3);this.InputBlockSize=blockSizeByte;this.OutputBlockSize=blockSizeByte;temp=new System.Byte(blockSizeByte);System.Buffer.BlockCopy(algo.IV,0,temp,0,Math.min(blockSizeByte,algo.IV.length));temp2=new System.Byte(blockSizeByte);feedBackByte=(algo.FeedbackSize>>3);if(feedBackByte!=0)feedBackIter=blockSizeByte/feedBackByte;workBuff=new System.Byte(blockSizeByte);workout=new System.Byte(blockSizeByte);};this.Initialize.apply(this,arguments);};System.Security.Cryptography.RNGCryptoServiceProvider=function(){var rnd;this.GetBytes=function(data){var length=data.length;for(var i=0;i<length;i++){data[i]=rnd.Next(0,256);}};this.GetNonZeroBytes=function(data){var length=data.length;for(var i=0;i<length;i++){data[i]=rnd.Next(1,256);}};this.Dispose=function(){m_disposed=true;};this.Initialize=function(){rnd=new System.Random();};this.Initialize.apply(this,arguments);};System.Security.Cryptography.CryptoStream=function(stream,transform,mode){this.Type="System.Security.Cryptography.CryptoStream";var _stream;var _transform;var _mode;var _currentBlock=new Array;var _disposed=false;var _flushedFinalBlock=false;var _partialCount=0;var _endOfStream=false;var _waitingBlock=new Array;var _waitingCount=0;var _transformedBlock=new Array;var _transformedPos=0;var _transformedCount=0;var _workingBlock=new Array;var _workingCount=0;this.Read=function(buffer,offset,count){var result=0;if((count==0)||((_transformedPos==_transformedCount)&&(_endOfStream))){return result;}if(_waitingBlock==null){_transformedBlock=new System.Byte(_transform.OutputBlockSize<<2);_transformedPos=0;_transformedCount=0;_waitingBlock=new System.Byte(_transform.InputBlockSize);_waitingCount=_stream.Read(_waitingBlock,0,_waitingBlock.length);}while(count>0){var length=(_transformedCount-_transformedPos);if(length<_transform.InputBlockSize){var transformed=0;_workingCount=_stream.Read(_workingBlock,0,_workingBlock.length);_endOfStream=(_workingCount<_transform.InputBlockSize);if(!_endOfStream){transformed=_transform.TransformBlock(_waitingBlock,0,_waitingBlock.length,_transformedBlock,_transformedCount);System.Buffer.BlockCopy(_workingBlock,0,_waitingBlock,0,_workingCount);_waitingCount=_workingCount;}else{if(_workingCount>0){transformed=_transform.TransformBlock(_waitingBlock,0,_waitingBlock.length,_transformedBlock,_transformedCount);System.Buffer.BlockCopy(_workingBlock,0,_waitingBlock,0,_workingCount);_waitingCount=_workingCount;length+=transformed;_transformedCount+=transformed;}var input=_transform.TransformFinalBlock(_waitingBlock,0,_waitingCount);transformed=input.length;System.Buffer.BlockCopy(input,0,_transformedBlock,_transformedCount,input.length);System.Array.Clear(input,0,input.length);}length+=transformed;_transformedCount+=transformed;}if(_transformedPos>_transform.InputBlockSize){System.Buffer.BlockCopy(_transformedBlock,_transformedPos,_transformedBlock,0,length);_transformedCount-=_transformedPos;_transformedPos=0;}length=((count<length)?count:length);if(length>0){System.Buffer.BlockCopy(_transformedBlock,_transformedPos,buffer,offset,length);_transformedPos+=length;result+=length;offset+=length;count-=length;}if(((length!=_transform.InputBlockSize)&&(_waitingCount!=_transform.InputBlockSize))||(_endOfStream)){count=0;}}return result;};this.Write=function(buffer,offset,count){if((_partialCount>0)&&(_partialCount!=_transform.InputBlockSize)){var remainder=_transform.InputBlockSize-_partialCount;remainder=((count<remainder)?count:remainder);System.Buffer.BlockCopy(buffer,offset,_workingBlock,_partialCount,remainder);_partialCount+=remainder;offset+=remainder;count-=remainder;}var bufferPos=offset;while(count>0){if(_partialCount==_transform.InputBlockSize){var len=_transform.TransformBlock(_workingBlock,0,_partialCount,_currentBlock,0);_stream.Write(_currentBlock,0,len);_partialCount=0;}if(_transform.CanTransformMultipleBlocks){var numBlock=Math.floor(((_partialCount+count)/_transform.InputBlockSize));var multiSize=(numBlock*_transform.InputBlockSize);if(numBlock>0){var multiBlocks=new System.Byte(multiSize);var len=_transform.TransformBlock(buffer,offset,multiSize,multiBlocks,0);_stream.Write(multiBlocks,0,len);_partialCount=count-multiSize;System.Buffer.BlockCopy(buffer,offset+multiSize,_workingBlock,0,_partialCount);}else{System.Buffer.BlockCopy(buffer,offset,_workingBlock,_partialCount,count);_partialCount+=count;}count=0;}else{var len=Math.min(_transform.InputBlockSize-_partialCount,count);System.Buffer.BlockCopy(buffer,bufferPos,_workingBlock,_partialCount,len);bufferPos+=len;_partialCount+=len;count-=len;}}};this.Flush=function(){if(_stream!=null)_stream.Flush();};this.FlushFinalBlock=function(){_flushedFinalBlock=true;var finalBuffer=_transform.TransformFinalBlock(_workingBlock,0,_partialCount);if(_stream!=null){_stream.Write(finalBuffer,0,finalBuffer.length);if(_stream.Type=="System.Security.Cryptography.CryptoStream"){_stream.FlushFinalBlock();}_stream.Flush();}System.Array.Clear(finalBuffer,0,finalBuffer.length);};this.ToArray=function(){return stream.ToArray();};this.Close=function(){if((!_flushedFinalBlock)&&(_mode==System.Security.Cryptography.CryptoStreamMode.Write)){this.FlushFinalBlock();}if(_stream!=null)_stream.Close();};this.Dispose=function(){if(!_disposed){_disposed=true;if(_workingBlock!=null)System.Array.Clear(_workingBlock,0,_workingBlock.length);if(_currentBlock!=null)System.Array.Clear(_currentBlock,0,_currentBlock.length);if(disposing){_stream=null;_workingBlock=null;_currentBlock=null;}}};this.Initialize=function(){_stream=arguments[0];_transform=arguments[1];_mode=arguments[2];_disposed=false;if(_transform){_workingBlock=new System.Byte(_transform.InputBlockSize);if(_mode==System.Security.Cryptography.CryptoStreamMode.Read){_currentBlock=new System.Byte(_transform.InputBlockSize);}else if(_mode==System.Security.Cryptography.CryptoStreamMode.Write){_currentBlock=new System.Byte(_transform.OutputBlockSize);}}};this.Initialize.apply(this,arguments);};System.Security.Cryptography.CipherMode={CBC:1,ECB:2,OFB:3,CFB:4,CTS:5};System.Security.Cryptography.PaddingMode={None:1,PKCS7:2,Zeros:3,ANSIX923:4,ISO10126:5};System.Security.Cryptography.CryptoStreamMode={Read:0,Write:1}