Icontem

File: libs/js/pidCrypt/javascripts/compressed/aes_ctr_c.js

Recommend this page to a friend!
  Classes of Jason Gerfen  >  jQuery.pidCrypt  >  libs/js/pidCrypt/javascripts/compressed/aes_ctr_c.js  >  Download  
File: libs/js/pidCrypt/javascripts/compressed/aes_ctr_c.js
Role: Application script
Content type: text/plain
Description: Application script
Class: jQuery.pidCrypt
Encrypt form values using RSA and AES
Author: By
Last change:
Date: 5 years ago
Size: 4,416 bytes
 

Contents

Class file image Download
if(typeof(pidCrypt)!="undefined"&&typeof(pidCrypt.AES)!="undefined"){pidCrypt.AES.CTR=function(){this.pidcrypt=new pidCrypt();this.aes=new pidCrypt.AES(this.pidcrypt);this.getOutput=function(){return this.pidcrypt.getOutput()};this.getAllMessages=function(a){return this.pidcrypt.getAllMessages(a)};this.isError=function(){return this.pidcrypt.isError()}};pidCrypt.AES.CTR.prototype.init=function(b,a){if(!a){a={}}if(!b){this.pidcrypt.appendError("pidCrypt.AES.CTR.initFromEncryption: Sorry, can not crypt or decrypt without password.\n")}this.pidcrypt.setDefaults();var d=this.pidcrypt.getParams();for(var c in a){d[c]=a[c]}d.password=b;d.key=b;d.dataOut="";this.pidcrypt.setParams(d);this.aes.init()};pidCrypt.AES.CTR.prototype.initEncrypt=function(c,b,a){this.init(b,a);this.pidcrypt.setParams({dataIn:c,encryptIn:pidCryptUtil.toByteArray(c)})};pidCrypt.AES.CTR.prototype.initDecrypt=function(e,b,a){var f={};this.init(b,a);f.dataIn=e;var d=pidCryptUtil.decodeBase64(e);var c=d.substr(0,8);f.salt=pidCryptUtil.convertToHex(c);d=d.substr(8);f.decryptIn=pidCryptUtil.toByteArray(d);this.pidcrypt.setParams(f)};pidCrypt.AES.CTR.prototype.getAllMessages=function(a){return this.pidcrypt.getAllMessages(a)};pidCrypt.AES.CTR.prototype.getCounterBlock=function(c){var b=new Array(c);var f=(new Date()).getTime();var e=Math.floor(f/1000);var a=f%1000;for(var d=0;d<4;d++){b[d]=(e>>>d*8)&255}for(d=0;d<4;d++){b[d+4]=a&255}return b.slice()};pidCrypt.AES.CTR.prototype.encryptRaw=function(k){var n=this.aes;var a=this.pidcrypt;var o=a.getParams();if(!k){k=o.encryptIn}a.setParams({encryptIn:k});var d=o.key;var h=Math.floor(o.nBits/8);var f=new Array(h);for(var s=0;s<h;s++){f[s]=isNaN(d.charCodeAt(s))?0:d.charCodeAt(s)}var x=n.encrypt(f.slice(0,16),n.expandKey(f));x=x.concat(x.slice(0,h-16));var e=this.getCounterBlock(o.blockSize);var l=pidCryptUtil.byteArray2String(e.slice(0,8));a.setParams({salt:pidCryptUtil.convertToHex(l)});var u=n.expandKey(x);var r=Math.ceil(k.length/o.blockSize);var j=new Array(r);for(var v=0;v<r;v++){for(var t=0;t<4;t++){e[15-t]=(v>>>t*8)&255}for(var t=0;t<4;t++){e[15-t-4]=(v/4294967296>>>t*8)}var g=n.encrypt(e,u);var q=v<r-1?o.blockSize:(k.length-1)%o.blockSize+1;var m=new Array(q);for(var s=0;s<q;s++){m[s]=g[s]^k[v*o.blockSize+s];m[s]=String.fromCharCode(m[s])}j[v]=m.join("")}var w=l+j.join("");a.setParams({dataOut:w,encryptOut:w});if(!a.isDebug()&&a.clear){a.clearParams()}return w};pidCrypt.AES.CTR.prototype.encrypt=function(b){var d=this.pidcrypt;var c=d.getParams();if(!b){b=c.dataIn}if(c.UTF8){b=pidCryptUtil.encodeUTF8(b);d.setParams({key:pidCryptUtil.encodeUTF8(d.getParam("key"))})}d.setParams({dataIn:b,encryptIn:pidCryptUtil.toByteArray(b)});var a=this.encryptRaw();a=pidCryptUtil.encodeBase64(a);d.setParams({dataOut:a});if(!d.isDebug()&&d.clear){d.clearParams()}return a};pidCrypt.AES.CTR.prototype.encryptText=function(c,b,a){this.initEncrypt(c,b,a);return this.encrypt()};pidCrypt.AES.CTR.prototype.decryptRaw=function(m){var d=this.pidcrypt;var o=this.aes;var q=d.getParams();if(!m){m=q.decryptIn}d.setParams({decryptIn:m});if(!q.dataIn){d.setParams({dataIn:m})}var l=Math.floor(q.nBits/8);var h=new Array(l);for(var r=0;r<l;r++){h[r]=isNaN(q.key.charCodeAt(r))?0:q.key.charCodeAt(r)}var w=o.encrypt(h.slice(0,16),o.expandKey(h));w=w.concat(w.slice(0,l-16));var f=new Array(8);var n=pidCryptUtil.convertFromHex(q.salt);for(r=0;r<8;r++){f[r]=n.charCodeAt(r)}var u=o.expandKey(w);var g=Math.ceil((m.length)/q.blockSize);var s=new Array(g);for(var v=0;v<g;v++){s[v]=m.slice(v*q.blockSize,v*q.blockSize+q.blockSize)}var a=new Array(s.length);var k=[];var e=[];for(v=0;v<g;v++){for(var t=0;t<4;t++){f[15-t]=((v)>>>t*8)&255}for(t=0;t<4;t++){f[15-t-4]=(((v+1)/4294967296-1)>>>t*8)&255}k=o.encrypt(f,u);e=new Array(s[v].length);for(r=0;r<s[v].length;r++){e[r]=k[r]^s[v][r];e[r]=String.fromCharCode(e[r])}a[v]=e.join("")}var j=a.join("");d.setParams({dataOut:j});if(!d.isDebug()&&d.clear){d.clearParams()}return j};pidCrypt.AES.CTR.prototype.decrypt=function(b){var d=this.pidcrypt;var c=d.getParams();if(b){d.setParams({dataIn:b,decryptIn:pidCryptUtil.toByteArray(b)})}if(c.UTF8){d.setParams({key:pidCryptUtil.encodeUTF8(d.getParam("key"))})}var a=this.decryptRaw();a=pidCryptUtil.decodeUTF8(a);d.setParams({dataOut:a});if(!d.isDebug()&&d.clear){d.clearParams()}return a};pidCrypt.AES.CTR.prototype.decryptText=function(c,b,a){this.initDecrypt(c,b,a);return this.decrypt()}};