﻿//-->
var System=System?System:{};System.Security=System.Security?System.Security:{};System.Security.Cryptography=System.Security.Cryptography?System.Security.Cryptography:{};System.Security.Cryptography.HMACSHA1=function(key){this.Type="System.Security.Cryptography.HMACSHA1";this.Name="HMACSHA1";this.Algorithm;this.Key;this.HashSize=160;this.HashName="SHA1";this.ComputeHash=function(key,data){if(!data){data=key;key=this.Key;}if(typeof(key)=="string")key=System.Text.Encoding.UTF8.GetBytes(key);if(typeof(data)=="string")data=System.Text.Encoding.UTF8.GetBytes(data);var hash=this.ComputeHashAsBin(key,data);var bytes=System.BitConverter.GetBytesFromIntegerArrayBe(hash);return bytes;};this.ComputeHashAsHex=function(key,data){var bytes=this.ComputeHash(key,data);return System.BitConverter.ToString(bytes,'');};this.ComputeHashAsBase64=function(key,data){var bytes=this.ComputeHash(key,data);return System.Convert.ToBase64String(bytes,false);};this.ComputeHashAsBin=function(key,data){if(!data){data=key;key=this.Key;}if(key.length>64)key=this.Algorithm.ComputeHash(key);var bkey=System.BitConverter.ToInt32ArrayBe(key,0);if(bkey.length>16)bkey=this.ComputeHashAsBin(bkey,key.length*this.Algorithm.chrsz);var ipad=Array(16),opad=Array(16);for(var i=0;i<16;i++){ipad[i]=bkey[i]^0x36363636;opad[i]=bkey[i]^0x5C5C5C5C;}var bData=System.BitConverter.ToInt32ArrayBe(data,0);var hash=this.Algorithm.ComputeHashAsBin(ipad.concat(bData),512+data.length*this.Algorithm.chrsz);return this.Algorithm.ComputeHashAsBin(opad.concat(hash),512+this.HashSize);};this.Test=function(){var isSuccess=this.ComputeHashAsHex("key","abc")=="4FD0B215276EF12F2B3E4C8ECAC2811498B656FC";return isSuccess;};this.Initialize=function(){this.Algorithm=new System.Security.Cryptography.SHA1();this.Key=arguments[0];};this.Initialize.apply(this,arguments);}
