/* https://www.github.com/jas-/jQuery.pidCrypt */
(function(a){a.fn.pidCrypt=function(c){var f=f||{appID:"",storage:"session",formID:a(this),type:"json",aes:"",keys:{},use:"",callback:function(){},preCallback:function(){},errCallback:function(){}};var e=e||{init:function(m){var l=d.__setup(m,f);a("body").removeData("use");b.__setup(l);a("#keyring").change(function(){a("body").data("use",b.__e(l,a(this).val()));l=d.__setup(m,f)});a("#"+l.formID.attr("id")).on("submit",function(n){n.preventDefault();d.__do(l,d.__gF(l))});return true}};var d=d||{__do:function(n,l){var m=(typeof l=="object")?k.__serialize(l):l;a.ajax({form:n.formID.attr("id"),url:n.formID.attr("action"),type:n.formID.attr("method"),data:m,dataType:n.type,crossDomain:(n.type==="jsonp")?true:false,beforeSend:function(o){o=d.__sH(n,o,m);((n.preCallback)&&(a.isFunction(n.preCallback)))?n.preCallback(o):false},success:function(o,p,q){(o)?j.__hR(o,n):false;((n.callback)&&(a.isFunction(n.callback)))?n.callback.call(o):console.log(o)},error:function(q,o,p){((n.errCallback)&&(a.isFunction(n.errCallback)))?n.errCallback.call(q,o,p):false}})},__setup:function(n,m){var l=a.extend({},m,n);l.aes=h.__sAES();l.keys=j.__existing(l);l.appID=(i.__vStr(l.appID))?l.appID:j.__gUUID(null);if(i.__szCk(l.keys)<=0){j.__hK(l)}l.use=(a("body").data("use"))?a("body").data("use"):j.__sK(l);return l},__gF:function(m){var l={};if(!i.__vStr(m.use)){m=d.__setup(m,f)}a.each(a("#"+m.formID.attr("id")+" :input, input:radio:selected, input:checkbox:checked, textarea"),function(o,n){if((i.__vStr(n.value))&&(i.__vStr(n.name))){l[n.name]=(parseInt(n.value.length)>80)?k.__sSplt(n.value):n.value}});return h.__eO(m,l)},__sH:function(n,m,l){m.setRequestHeader("X-Alt-Referer",n.appID);if(i.__vStr(j.__gT(document.cookie))){m.setRequestHeader("X-Token",j.__gT(document.cookie))}if(i.__vStr(l)){m.setRequestHeader("Content-MD5",pidCryptUtil.encodeBase64(pidCrypt.MD5(l)))}else{m.setRequestHeader("Content-MD5",pidCryptUtil.encodeBase64(pidCrypt.MD5(n.appID)))}if(!l){m.setRequestHeader("Access-Control-Allow-Origin",j.__id());m.setRequestHeader("Access-Control-Allow-Methods","POST");m.setRequestHeader("Content-Type","application/json")}return m}};var j=j||{__hK:function(l){var m=function(){var q=(this)?this:false;var n=((q)&&(q.email))?q.email:l.appID;var o=((q)&&(q.key))?q.key:false;if(!o){return false}var p={};p[l.appID]={};p[l.appID]["email"]=h.__e(l.aes,n,l.appID);p[l.appID]["key"]=h.__e(l.aes,o,l.appID);p=a.extend({},p,j.__existing(l));g.__sI(l.storage,j.__id(),JSON.stringify(p))};l.callback=m;d.__do(l,{key:true});return true},__sK:function(m){var l=false;if(i.__szCk(m.keys)>0){a.each(m.keys,function(p,o){var q=/[0-9a-z-_.]{2,45}\@[0-9a-z-_.]{2,45}\.[a-z]{2,4}/i;var n=h.__d(m.aes,o.email,p);if(q.test(n)){l=h.__d(m.aes,o.key,p);return false}else{l=h.__d(m.aes,o.key,p)}})}return l},__existing:function(l){return(g.__gI(l.storage,j.__id()))?JSON.parse(g.__gI(l.storage,j.__id())):false},__id:function(){return(i.__vStr(location.host))?location.host:(i.__vStr(location.hostname))?location.hostname:"localhost"},__gUUID:function(l){var q="0123456789abcdef".split("");var o=[],n=Math.random,p;o[8]=o[13]=o[18]=o[23]="-";o[14]="4";for(var m=0;m<36;m++){if(!o[m]){p=0|n()*16;o[m]=q[(m==19)?(p&3)|8:p&15]}}return(l!==null)?o.join("").replace(/-/g,"").split("",l).join(""):o.join("")},__strIV:function(l){return(l)?encodeURI(l.replace(/-/gi,"").substring(16,Math.ceil(16*l.length)%l.length)):false},__hR:function(m,n){var l=false;if(i.__szCk(m)>0){a.each(m,function(p,o){if((p==="keyring")&&(i.__vStr(o.email))){if(!j.__hlpr(n,o.email)){var q=j.__gUUID(null);var r={};r[q]={};r[q]["email"]=h.__e(n.aes,o.email,q);r[q]["key"]=h.__e(n.aes,o.key,q);r=a.extend({},r,j.__existing(n));g.__sI(n.storage,j.__id(),JSON.stringify(r))}}})}return l},__hlpr:function(n,l){var m=false;a.each(j.__existing(n),function(p,o){if(h.__d(n.aes,o.email,p)==l){m=true}});return m},__gT:function(n){var m=false;var l=n.split(";");a.each(l,function(p,o){if(o.match("token=")){m=o.substr(o.indexOf("=")+1)}});return m}};var h=h||{__eO:function(n,m){var l={};var p=h.__certParser(n.use);h.__iP(p);if(i.__szCk(m)>0){a.each(m,function(q,o){if(typeof o==="object"){l[q]={};a.each(o,function(s,r){l[q][s]=pidCrypt.RSA.prototype.encrypt(r)})}else{l[q]=pidCrypt.RSA.prototype.encrypt(o)}})}else{l=0}return l},__sAES:function(){return new pidCrypt.AES.CBC()},__iP:function(p){var o=false;if(p.b64){var m=pidCryptUtil.decodeBase64(p.b64);o=new pidCrypt();var n=pidCrypt.ASN1.decode(pidCryptUtil.toByteArray(m));var l=n.toHexTree();pidCrypt.RSA.prototype.setPublicKeyFromASN(l)}return o},__certParser:function(q){if(!q){return false}var v=q.split("\n");var l=false;var m=false;var n=false;var s="";var o={};o.info="";o.salt="";o.iv;o.b64="";o.aes=false;o.mode="";o.bits=0;for(var r=0;r<v.length;r++){s=v[r].substr(0,9);if(r==1&&s!="Proc-Type"&&s.indexOf("M")==0){m=true}switch(s){case"-----BEGI":l=true;break;case"Proc-Type":if(l){o.info=v[r]}break;case"DEK-Info:":if(l){var p=v[r].split(",");var u=p[0].split(": ");var t=u[1].split("-");o.aes=(t[0]=="AES")?true:false;o.mode=t[2];o.bits=parseInt(t[1]);o.salt=p[1].substr(0,16);o.iv=p[1]}break;case"":if(l){m=true}break;case"-----END ":if(l){m=false;l=false}break;default:if(l&&m){o.b64+=pidCryptUtil.stripLineFeeds(v[r])}}}return o},__e:function(n,m,l){return encodeURI(n.encryptText(m,pidCrypt.SHA512(l),{nBits:256,salt:j.__strIV(pidCrypt.SHA512(l))}))},__d:function(n,m,l){return decodeURI(n.decryptText(m,pidCrypt.SHA512(l),{nBits:256,salt:j.__strIV(pidCrypt.SHA512(l))}))}};var k=k||{__serialize:function(m){if(i.__szCk(m)>0){var l="";a.each(m,function(o,n){if(typeof n==="object"){a.each(n,function(q,p){l+=o+"["+q+"]="+p+"&"})}else{l+=o+"="+n+"&"}});l=l.substring(0,l.length-1)}else{return false}return l},__sSplt:function(p){var n=p.length/80;var q={};var l=0;var o=80;for(var m=0;m<n;m++){if(m>0){l=l+80;o=o+80}if(p.slice(l,o).length>0){q[m]=p.slice(l,o)}}return q}};var g=g||{__sI:function(o,n,m){var l=false;o=(i.__vStore(o+"Storage"))?o:"cookie";switch(o){case"local":l=this.__sL(n,m);break;case"session":l=this.__sS(n,m);break;case"cookie":l=this.__sC(n,m);break;default:l=this.__sL(n,m);break}return l},__gI:function(n,m){var l=false;n=(i.__vStore(n+"Storage"))?n:"cookie";switch(n){case"local":l=this.__gL(m);break;case"session":l=this.__gS(m);break;case"cookie":l=this.__gC(m);break;default:l=this.__gL(m);break}return l},__dI:function(n,m){var l=false;n=(i.__vStore(n+"Storage"))?n:"cookie";switch(n){case"local":l=this.__dL(m);break;case"session":l=this.__dS(m);break;case"cookie":l=this.__dC(m);break;default:l=this.__dL(m);break}return l},__sL:function(m,l){return(localStorage.setItem(m,l))?false:true},__sS:function(m,l){return(sessionStorage.setItem(m,l))?false:true},__sC:function(m,l){if(typeof a.cookie==="function"){return(a.cookie(m,l,{expires:7}))?true:false}else{return false}},__gL:function(l){return(localStorage.getItem(l))?localStorage.getItem(l):false},__gS:function(l){return(sessionStorage.getItem(l))?sessionStorage.getItem(l):false},__gC:function(l){if(typeof a.cookie==="function"){return(a.cookie(l))?a.cookie(l):false}else{return false}},__dL:function(l){return(localStorage.removeItem(l))?localStorage.removeItem(l):false},__dS:function(l){return(sessionStorage.removeItem(l))?sessionStorage.removeItem(l):false},__dC:function(l){if(typeof a.cookie==="function"){return(a.cookie(l,"",{expires:-7}))?true:false}else{return false}}};var i=i||{__vStr:function(l){if(!l){return false}return((l==false)||(l.length==0)||(!l)||(l==null)||(l=="")||(typeof l=="undefined"))?false:true},__vStore:function(l){try{return((l in window)&&(window[l]))?true:false}catch(m){return false}},__szCk:function(l){var m=0;a.each(l,function(o,n){if(l.hasOwnProperty(o)){m++}});return m}};var b=b||{__setup:function(m){if(i.__szCk(m.keys)>=3){var l='<div id="overlay"></div><div id="modal"><div id="content">'+b.__aK(m)+"</div></div>";a("#"+m.formID.attr("name")).prepend(l);a("body").css({overflow:"hidden"});a("#overlay").css({position:"fixed",top:0,left:0,width:"100%",height:"100%",background:"#000",opacity:0.5,filter:"alpha(opacity=50)"});a("#modal").css({position:"absolute",background:"rgba(0,0,0,0.2)","border-radius":"14px",padding:"8px"});a("#content").css({"border-radius":"8px",background:"#fff",padding:"20px"})}},__e:function(m,l){a.each(m.keys,function(o,n){if(h.__d(m.aes,n.email,o)==l){m.use=h.__d(m.aes,n.key,o);a("#keyring, #content, #modal, #overlay").hide();a("body").css({overflow:"auto"})}});return m.use},__aK:function(r){var q=i.__szCk(r.keys);var l=(q>=5)?5:q;var m,n="";if(q>=3){var p="";m='<label for="keyring">Select your email:</label><select name="keyring" id="keyring" size="'+l+'" multiple>';a.each(r.keys,function(s,o){p=h.__d(r.aes,o.email,s);n=/[0-9a-z-_.]{2,45}\@[0-9a-z-_.]{2,45}\.[a-z]{2,4}/i;if(n.test(p)){m=m+'<option value="'+p+'">'+p+"</option>"}});m=m+"</select>"}return m}};if(e[c]){return e[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if((typeof c==="object")||(!c)){return e.init.apply(this,arguments)}else{console.log("Method "+c+" does not exist")}}}})(jQuery); |