UNPKG

node-jsrsasign

Version:

pure JavaScript cryptographic library(jsrsasign) and JSON Web Token (JWT) and JSON Web Signature (JWS) library (jsjws) bundle

1,368 lines (1,264 loc) 560 kB
var navigator = {}; var window = {}; // ./lib/yahoo-min.js /* Copyright (c) 2011, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html version: 2.9.0 */ if(typeof YAHOO=="undefined"||!YAHOO){var YAHOO={};}YAHOO.namespace=function(){var b=arguments,g=null,e,c,f;for(e=0;e<b.length;e=e+1){f=(""+b[e]).split(".");g=YAHOO;for(c=(f[0]=="YAHOO")?1:0;c<f.length;c=c+1){g[f[c]]=g[f[c]]||{};g=g[f[c]];}}return g;};YAHOO.log=function(d,a,c){var b=YAHOO.widget.Logger;if(b&&b.log){return b.log(d,a,c);}else{return false;}};YAHOO.register=function(a,f,e){var k=YAHOO.env.modules,c,j,h,g,d;if(!k[a]){k[a]={versions:[],builds:[]};}c=k[a];j=e.version;h=e.build;g=YAHOO.env.listeners;c.name=a;c.version=j;c.build=h;c.versions.push(j);c.builds.push(h);c.mainClass=f;for(d=0;d<g.length;d=d+1){g[d](c);}if(f){f.VERSION=j;f.BUILD=h;}else{YAHOO.log("mainClass is undefined for module "+a,"warn");}};YAHOO.env=YAHOO.env||{modules:[],listeners:[]};YAHOO.env.getVersion=function(a){return YAHOO.env.modules[a]||null;};YAHOO.env.parseUA=function(d){var e=function(i){var j=0;return parseFloat(i.replace(/\./g,function(){return(j++==1)?"":".";}));},h=navigator,g={ie:0,opera:0,gecko:0,webkit:0,chrome:0,mobile:null,air:0,ipad:0,iphone:0,ipod:0,ios:null,android:0,webos:0,caja:h&&h.cajaVersion,secure:false,os:null},c=d||(navigator&&navigator.userAgent),f=window&&window.location,b=f&&f.href,a;g.secure=b&&(b.toLowerCase().indexOf("https")===0);if(c){if((/windows|win32/i).test(c)){g.os="windows";}else{if((/macintosh/i).test(c)){g.os="macintosh";}else{if((/rhino/i).test(c)){g.os="rhino";}}}if((/KHTML/).test(c)){g.webkit=1;}a=c.match(/AppleWebKit\/([^\s]*)/);if(a&&a[1]){g.webkit=e(a[1]);if(/ Mobile\//.test(c)){g.mobile="Apple";a=c.match(/OS ([^\s]*)/);if(a&&a[1]){a=e(a[1].replace("_","."));}g.ios=a;g.ipad=g.ipod=g.iphone=0;a=c.match(/iPad|iPod|iPhone/);if(a&&a[0]){g[a[0].toLowerCase()]=g.ios;}}else{a=c.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/);if(a){g.mobile=a[0];}if(/webOS/.test(c)){g.mobile="WebOS";a=c.match(/webOS\/([^\s]*);/);if(a&&a[1]){g.webos=e(a[1]);}}if(/ Android/.test(c)){g.mobile="Android";a=c.match(/Android ([^\s]*);/);if(a&&a[1]){g.android=e(a[1]);}}}a=c.match(/Chrome\/([^\s]*)/);if(a&&a[1]){g.chrome=e(a[1]);}else{a=c.match(/AdobeAIR\/([^\s]*)/);if(a){g.air=a[0];}}}if(!g.webkit){a=c.match(/Opera[\s\/]([^\s]*)/);if(a&&a[1]){g.opera=e(a[1]);a=c.match(/Version\/([^\s]*)/);if(a&&a[1]){g.opera=e(a[1]);}a=c.match(/Opera Mini[^;]*/);if(a){g.mobile=a[0];}}else{a=c.match(/MSIE\s([^;]*)/);if(a&&a[1]){g.ie=e(a[1]);}else{a=c.match(/Gecko\/([^\s]*)/);if(a){g.gecko=1;a=c.match(/rv:([^\s\)]*)/);if(a&&a[1]){g.gecko=e(a[1]);}}}}}}return g;};YAHOO.env.ua=YAHOO.env.parseUA();(function(){YAHOO.namespace("util","widget","example");if("undefined"!==typeof YAHOO_config){var b=YAHOO_config.listener,a=YAHOO.env.listeners,d=true,c;if(b){for(c=0;c<a.length;c++){if(a[c]==b){d=false;break;}}if(d){a.push(b);}}}})();YAHOO.lang=YAHOO.lang||{};(function(){var f=YAHOO.lang,a=Object.prototype,c="[object Array]",h="[object Function]",i="[object Object]",b=[],g={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;"},d=["toString","valueOf"],e={isArray:function(j){return a.toString.apply(j)===c;},isBoolean:function(j){return typeof j==="boolean";},isFunction:function(j){return(typeof j==="function")||a.toString.apply(j)===h;},isNull:function(j){return j===null;},isNumber:function(j){return typeof j==="number"&&isFinite(j);},isObject:function(j){return(j&&(typeof j==="object"||f.isFunction(j)))||false;},isString:function(j){return typeof j==="string";},isUndefined:function(j){return typeof j==="undefined";},_IEEnumFix:(YAHOO.env.ua.ie)?function(l,k){var j,n,m;for(j=0;j<d.length;j=j+1){n=d[j];m=k[n];if(f.isFunction(m)&&m!=a[n]){l[n]=m;}}}:function(){},escapeHTML:function(j){return j.replace(/[&<>"'\/`]/g,function(k){return g[k];});},extend:function(m,n,l){if(!n||!m){throw new Error("extend failed, please check that "+"all dependencies are included.");}var k=function(){},j;k.prototype=n.prototype;m.prototype=new k();m.prototype.constructor=m;m.superclass=n.prototype;if(n.prototype.constructor==a.constructor){n.prototype.constructor=n;}if(l){for(j in l){if(f.hasOwnProperty(l,j)){m.prototype[j]=l[j];}}f._IEEnumFix(m.prototype,l);}},augmentObject:function(n,m){if(!m||!n){throw new Error("Absorb failed, verify dependencies.");}var j=arguments,l,o,k=j[2];if(k&&k!==true){for(l=2;l<j.length;l=l+1){n[j[l]]=m[j[l]];}}else{for(o in m){if(k||!(o in n)){n[o]=m[o];}}f._IEEnumFix(n,m);}return n;},augmentProto:function(m,l){if(!l||!m){throw new Error("Augment failed, verify dependencies.");}var j=[m.prototype,l.prototype],k;for(k=2;k<arguments.length;k=k+1){j.push(arguments[k]);}f.augmentObject.apply(this,j);return m;},dump:function(j,p){var l,n,r=[],t="{...}",k="f(){...}",q=", ",m=" => ";if(!f.isObject(j)){return j+"";}else{if(j instanceof Date||("nodeType" in j&&"tagName" in j)){return j;}else{if(f.isFunction(j)){return k;}}}p=(f.isNumber(p))?p:3;if(f.isArray(j)){r.push("[");for(l=0,n=j.length;l<n;l=l+1){if(f.isObject(j[l])){r.push((p>0)?f.dump(j[l],p-1):t);}else{r.push(j[l]);}r.push(q);}if(r.length>1){r.pop();}r.push("]");}else{r.push("{");for(l in j){if(f.hasOwnProperty(j,l)){r.push(l+m);if(f.isObject(j[l])){r.push((p>0)?f.dump(j[l],p-1):t);}else{r.push(j[l]);}r.push(q);}}if(r.length>1){r.pop();}r.push("}");}return r.join("");},substitute:function(x,y,E,l){var D,C,B,G,t,u,F=[],p,z=x.length,A="dump",r=" ",q="{",m="}",n,w;for(;;){D=x.lastIndexOf(q,z);if(D<0){break;}C=x.indexOf(m,D);if(D+1>C){break;}p=x.substring(D+1,C);G=p;u=null;B=G.indexOf(r);if(B>-1){u=G.substring(B+1);G=G.substring(0,B);}t=y[G];if(E){t=E(G,t,u);}if(f.isObject(t)){if(f.isArray(t)){t=f.dump(t,parseInt(u,10));}else{u=u||"";n=u.indexOf(A);if(n>-1){u=u.substring(4);}w=t.toString();if(w===i||n>-1){t=f.dump(t,parseInt(u,10));}else{t=w;}}}else{if(!f.isString(t)&&!f.isNumber(t)){t="~-"+F.length+"-~";F[F.length]=p;}}x=x.substring(0,D)+t+x.substring(C+1);if(l===false){z=D-1;}}for(D=F.length-1;D>=0;D=D-1){x=x.replace(new RegExp("~-"+D+"-~"),"{"+F[D]+"}","g");}return x;},trim:function(j){try{return j.replace(/^\s+|\s+$/g,"");}catch(k){return j; }},merge:function(){var n={},k=arguments,j=k.length,m;for(m=0;m<j;m=m+1){f.augmentObject(n,k[m],true);}return n;},later:function(t,k,u,n,p){t=t||0;k=k||{};var l=u,s=n,q,j;if(f.isString(u)){l=k[u];}if(!l){throw new TypeError("method undefined");}if(!f.isUndefined(n)&&!f.isArray(s)){s=[n];}q=function(){l.apply(k,s||b);};j=(p)?setInterval(q,t):setTimeout(q,t);return{interval:p,cancel:function(){if(this.interval){clearInterval(j);}else{clearTimeout(j);}}};},isValue:function(j){return(f.isObject(j)||f.isString(j)||f.isNumber(j)||f.isBoolean(j));}};f.hasOwnProperty=(a.hasOwnProperty)?function(j,k){return j&&j.hasOwnProperty&&j.hasOwnProperty(k);}:function(j,k){return !f.isUndefined(j[k])&&j.constructor.prototype[k]!==j[k];};e.augmentObject(f,e,true);YAHOO.util.Lang=f;f.augment=f.augmentProto;YAHOO.augment=f.augmentProto;YAHOO.extend=f.extend;})();YAHOO.register("yahoo",YAHOO,{version:"2.9.0",build:"2800"}); // ./lib/jsrsasign/ext/base64.js /*! (c) Tom Wu | http://www-cs-students.stanford.edu/~tjw/jsbn/ */ 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); } if (b64pad) while((ret.length & 3) > 0) ret += b64pad; return ret; } // convert a base64 string to hex function b64tohex(s) { var ret = "" var i; var k = 0; // b64 state, 0-3 var slop; var v; for(i = 0; i < s.length; ++i) { if(s.charAt(i) == b64pad) break; v = b64map.indexOf(s.charAt(i)); if(v < 0) continue; if(k == 0) { ret += int2char(v >> 2); slop = v & 3; k = 1; } else if(k == 1) { ret += int2char((slop << 2) | (v >> 4)); slop = v & 0xf; 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 & 0xf); k = 0; } } if(k == 1) ret += int2char(slop << 2); return ret; } // convert a base64 string to a byte/number array function b64toBA(s) { //piggyback on b64tohex for now, optimize later var h = b64tohex(s); var i; var a = new Array(); for(i = 0; 2*i < h.length; ++i) { a[i] = parseInt(h.substring(2*i,2*i+2),16); } return a; } // ./lib/jsrsasign/crypto-1.1.js /*! crypto-1.1.5.js (c) 2013 Kenji Urushima | kjur.github.com/jsrsasign/license */ /* * crypto.js - Cryptographic Algorithm Provider class * * Copyright (c) 2013 Kenji Urushima (kenji.urushima@gmail.com) * * This software is licensed under the terms of the MIT License. * http://kjur.github.com/jsrsasign/license * * The above copyright and license notice shall be * included in all copies or substantial portions of the Software. */ /** * @fileOverview * @name crypto-1.1.js * @author Kenji Urushima kenji.urushima@gmail.com * @version 1.1.5 (2013-Oct-06) * @since jsrsasign 2.2 * @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a> */ /** * kjur's class library name space * @name KJUR * @namespace kjur's class library name space */ if (typeof KJUR == "undefined" || !KJUR) KJUR = {}; /** * kjur's cryptographic algorithm provider library name space * <p> * This namespace privides following crytpgrahic classes. * <ul> * <li>{@link KJUR.crypto.MessageDigest} - Java JCE(cryptograhic extension) style MessageDigest class</li> * <li>{@link KJUR.crypto.Signature} - Java JCE(cryptograhic extension) style Signature class</li> * <li>{@link KJUR.crypto.Util} - cryptographic utility functions and properties</li> * </ul> * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2. * </p> * @name KJUR.crypto * @namespace */ if (typeof KJUR.crypto == "undefined" || !KJUR.crypto) KJUR.crypto = {}; /** * static object for cryptographic function utilities * @name KJUR.crypto.Util * @class static object for cryptographic function utilities * @property {Array} DIGESTINFOHEAD PKCS#1 DigestInfo heading hexadecimal bytes for each hash algorithms * @property {Array} DEFAULTPROVIDER associative array of default provider name for each hash and signature algorithms * @description */ KJUR.crypto.Util = new function() { this.DIGESTINFOHEAD = { 'sha1': "3021300906052b0e03021a05000414", 'sha224': "302d300d06096086480165030402040500041c", 'sha256': "3031300d060960864801650304020105000420", 'sha384': "3041300d060960864801650304020205000430", 'sha512': "3051300d060960864801650304020305000440", 'md2': "3020300c06082a864886f70d020205000410", 'md5': "3020300c06082a864886f70d020505000410", 'ripemd160': "3021300906052b2403020105000414", }; /* * @since crypto 1.1.1 */ this.DEFAULTPROVIDER = { 'md5': 'cryptojs', 'sha1': 'cryptojs', 'sha224': 'cryptojs', 'sha256': 'cryptojs', 'sha384': 'cryptojs', 'sha512': 'cryptojs', 'ripemd160': 'cryptojs', 'hmacmd5': 'cryptojs', 'hmacsha1': 'cryptojs', 'hmacsha224': 'cryptojs', 'hmacsha256': 'cryptojs', 'hmacsha384': 'cryptojs', 'hmacsha512': 'cryptojs', 'hmacripemd160': 'cryptojs', 'MD5withRSA': 'cryptojs/jsrsa', 'SHA1withRSA': 'cryptojs/jsrsa', 'SHA224withRSA': 'cryptojs/jsrsa', 'SHA256withRSA': 'cryptojs/jsrsa', 'SHA384withRSA': 'cryptojs/jsrsa', 'SHA512withRSA': 'cryptojs/jsrsa', 'RIPEMD160withRSA': 'cryptojs/jsrsa', 'MD5withECDSA': 'cryptojs/jsrsa', 'SHA1withECDSA': 'cryptojs/jsrsa', 'SHA224withECDSA': 'cryptojs/jsrsa', 'SHA256withECDSA': 'cryptojs/jsrsa', 'SHA384withECDSA': 'cryptojs/jsrsa', 'SHA512withECDSA': 'cryptojs/jsrsa', 'RIPEMD160withECDSA': 'cryptojs/jsrsa', 'SHA1withDSA': 'cryptojs/jsrsa', 'SHA224withDSA': 'cryptojs/jsrsa', 'SHA256withDSA': 'cryptojs/jsrsa', 'MD5withRSAandMGF1': 'cryptojs/jsrsa', 'SHA1withRSAandMGF1': 'cryptojs/jsrsa', 'SHA224withRSAandMGF1': 'cryptojs/jsrsa', 'SHA256withRSAandMGF1': 'cryptojs/jsrsa', 'SHA384withRSAandMGF1': 'cryptojs/jsrsa', 'SHA512withRSAandMGF1': 'cryptojs/jsrsa', 'RIPEMD160withRSAandMGF1': 'cryptojs/jsrsa', }; /* * @since crypto 1.1.2 */ this.CRYPTOJSMESSAGEDIGESTNAME = { 'md5': 'CryptoJS.algo.MD5', 'sha1': 'CryptoJS.algo.SHA1', 'sha224': 'CryptoJS.algo.SHA224', 'sha256': 'CryptoJS.algo.SHA256', 'sha384': 'CryptoJS.algo.SHA384', 'sha512': 'CryptoJS.algo.SHA512', 'ripemd160': 'CryptoJS.algo.RIPEMD160' }; /** * get hexadecimal DigestInfo * @name getDigestInfoHex * @memberOf KJUR.crypto.Util * @function * @param {String} hHash hexadecimal hash value * @param {String} alg hash algorithm name (ex. 'sha1') * @return {String} hexadecimal string DigestInfo ASN.1 structure */ this.getDigestInfoHex = function(hHash, alg) { if (typeof this.DIGESTINFOHEAD[alg] == "undefined") throw "alg not supported in Util.DIGESTINFOHEAD: " + alg; return this.DIGESTINFOHEAD[alg] + hHash; }; /** * get PKCS#1 padded hexadecimal DigestInfo * @name getPaddedDigestInfoHex * @memberOf KJUR.crypto.Util * @function * @param {String} hHash hexadecimal hash value of message to be signed * @param {String} alg hash algorithm name (ex. 'sha1') * @param {Integer} keySize key bit length (ex. 1024) * @return {String} hexadecimal string of PKCS#1 padded DigestInfo */ this.getPaddedDigestInfoHex = function(hHash, alg, keySize) { var hDigestInfo = this.getDigestInfoHex(hHash, alg); var pmStrLen = keySize / 4; // minimum PM length if (hDigestInfo.length + 22 > pmStrLen) // len(0001+ff(*8)+00+hDigestInfo)=22 throw "key is too short for SigAlg: keylen=" + keySize + "," + alg; var hHead = "0001"; var hTail = "00" + hDigestInfo; var hMid = ""; var fLen = pmStrLen - hHead.length - hTail.length; for (var i = 0; i < fLen; i += 2) { hMid += "ff"; } var hPaddedMessage = hHead + hMid + hTail; return hPaddedMessage; }; /** * get hexadecimal hash of string with specified algorithm * @name hashString * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @param {String} alg hash algorithm name * @return {String} hexadecimal string of hash value * @since 1.1.1 */ this.hashString = function(s, alg) { var md = new KJUR.crypto.MessageDigest({'alg': alg}); return md.digestString(s); }; /** * get hexadecimal hash of hexadecimal string with specified algorithm * @name hashHex * @memberOf KJUR.crypto.Util * @function * @param {String} sHex input hexadecimal string to be hashed * @param {String} alg hash algorithm name * @return {String} hexadecimal string of hash value * @since 1.1.1 */ this.hashHex = function(sHex, alg) { var md = new KJUR.crypto.MessageDigest({'alg': alg}); return md.digestHex(sHex); }; /** * get hexadecimal SHA1 hash of string * @name sha1 * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @return {String} hexadecimal string of hash value * @since 1.0.3 */ this.sha1 = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'sha1', 'prov':'cryptojs'}); return md.digestString(s); }; /** * get hexadecimal SHA256 hash of string * @name sha256 * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @return {String} hexadecimal string of hash value * @since 1.0.3 */ this.sha256 = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'}); return md.digestString(s); }; this.sha256Hex = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'sha256', 'prov':'cryptojs'}); return md.digestHex(s); }; /** * get hexadecimal SHA512 hash of string * @name sha512 * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @return {String} hexadecimal string of hash value * @since 1.0.3 */ this.sha512 = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'}); return md.digestString(s); }; this.sha512Hex = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'sha512', 'prov':'cryptojs'}); return md.digestHex(s); }; /** * get hexadecimal MD5 hash of string * @name md5 * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @return {String} hexadecimal string of hash value * @since 1.0.3 */ this.md5 = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'md5', 'prov':'cryptojs'}); return md.digestString(s); }; /** * get hexadecimal RIPEMD160 hash of string * @name ripemd160 * @memberOf KJUR.crypto.Util * @function * @param {String} s input string to be hashed * @return {String} hexadecimal string of hash value * @since 1.0.3 */ this.ripemd160 = function(s) { var md = new KJUR.crypto.MessageDigest({'alg':'ripemd160', 'prov':'cryptojs'}); return md.digestString(s); }; /* * @since 1.1.2 */ this.getCryptoJSMDByName = function(s) { }; }; /** * MessageDigest class which is very similar to java.security.MessageDigest class * @name KJUR.crypto.MessageDigest * @class MessageDigest class which is very similar to java.security.MessageDigest class * @param {Array} params parameters for constructor * @description * <br/> * Currently this supports following algorithm and providers combination: * <ul> * <li>md5 - cryptojs</li> * <li>sha1 - cryptojs</li> * <li>sha224 - cryptojs</li> * <li>sha256 - cryptojs</li> * <li>sha384 - cryptojs</li> * <li>sha512 - cryptojs</li> * <li>ripemd160 - cryptojs</li> * <li>sha256 - sjcl (NEW from crypto.js 1.0.4)</li> * </ul> * @example * // CryptoJS provider sample * &lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core.js"&gt;&lt;/script&gt; * &lt;script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/sha1.js"&gt;&lt;/script&gt; * &lt;script src="crypto-1.0.js"&gt;&lt;/script&gt; * var md = new KJUR.crypto.MessageDigest({alg: "sha1", prov: "cryptojs"}); * md.updateString('aaa') * var mdHex = md.digest() * * // SJCL(Stanford JavaScript Crypto Library) provider sample * &lt;script src="http://bitwiseshiftleft.github.io/sjcl/sjcl.js"&gt;&lt;/script&gt; * &lt;script src="crypto-1.0.js"&gt;&lt;/script&gt; * var md = new KJUR.crypto.MessageDigest({alg: "sha256", prov: "sjcl"}); // sjcl supports sha256 only * md.updateString('aaa') * var mdHex = md.digest() */ KJUR.crypto.MessageDigest = function(params) { var md = null; var algName = null; var provName = null; /** * set hash algorithm and provider * @name setAlgAndProvider * @memberOf KJUR.crypto.MessageDigest * @function * @param {String} alg hash algorithm name * @param {String} prov provider name * @description * @example * // for SHA1 * md.setAlgAndProvider('sha1', 'cryptojs'); * // for RIPEMD160 * md.setAlgAndProvider('ripemd160', 'cryptojs'); */ this.setAlgAndProvider = function(alg, prov) { if (alg != null && prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg]; // for cryptojs if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(alg) != -1 && prov == 'cryptojs') { try { this.md = eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[alg]).create(); } catch (ex) { throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex; } this.updateString = function(str) { this.md.update(str); }; this.updateHex = function(hex) { var wHex = CryptoJS.enc.Hex.parse(hex); this.md.update(wHex); }; this.digest = function() { var hash = this.md.finalize(); return hash.toString(CryptoJS.enc.Hex); }; this.digestString = function(str) { this.updateString(str); return this.digest(); }; this.digestHex = function(hex) { this.updateHex(hex); return this.digest(); }; } if (':sha256:'.indexOf(alg) != -1 && prov == 'sjcl') { try { this.md = new sjcl.hash.sha256(); } catch (ex) { throw "setAlgAndProvider hash alg set fail alg=" + alg + "/" + ex; } this.updateString = function(str) { this.md.update(str); }; this.updateHex = function(hex) { var baHex = sjcl.codec.hex.toBits(hex); this.md.update(baHex); }; this.digest = function() { var hash = this.md.finalize(); return sjcl.codec.hex.fromBits(hash); }; this.digestString = function(str) { this.updateString(str); return this.digest(); }; this.digestHex = function(hex) { this.updateHex(hex); return this.digest(); }; } }; /** * update digest by specified string * @name updateString * @memberOf KJUR.crypto.MessageDigest * @function * @param {String} str string to update * @description * @example * md.updateString('New York'); */ this.updateString = function(str) { throw "updateString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName; }; /** * update digest by specified hexadecimal string * @name updateHex * @memberOf KJUR.crypto.MessageDigest * @function * @param {String} hex hexadecimal string to update * @description * @example * md.updateHex('0afe36'); */ this.updateHex = function(hex) { throw "updateHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName; }; /** * completes hash calculation and returns hash result * @name digest * @memberOf KJUR.crypto.MessageDigest * @function * @description * @example * md.digest() */ this.digest = function() { throw "digest() not supported for this alg/prov: " + this.algName + "/" + this.provName; }; /** * performs final update on the digest using string, then completes the digest computation * @name digestString * @memberOf KJUR.crypto.MessageDigest * @function * @param {String} str string to final update * @description * @example * md.digestString('aaa') */ this.digestString = function(str) { throw "digestString(str) not supported for this alg/prov: " + this.algName + "/" + this.provName; }; /** * performs final update on the digest using hexadecimal string, then completes the digest computation * @name digestHex * @memberOf KJUR.crypto.MessageDigest * @function * @param {String} hex hexadecimal string to final update * @description * @example * md.digestHex('0f2abd') */ this.digestHex = function(hex) { throw "digestHex(hex) not supported for this alg/prov: " + this.algName + "/" + this.provName; }; if (params !== undefined) { if (params['alg'] !== undefined) { this.algName = params['alg']; if (params['prov'] === undefined) this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]; this.setAlgAndProvider(this.algName, this.provName); } } }; /** * Mac(Message Authentication Code) class which is very similar to java.security.Mac class * @name KJUR.crypto.Mac * @class Mac class which is very similar to java.security.Mac class * @param {Array} params parameters for constructor * @description * <br/> * Currently this supports following algorithm and providers combination: * <ul> * <li>hmacmd5 - cryptojs</li> * <li>hmacsha1 - cryptojs</li> * <li>hmacsha224 - cryptojs</li> * <li>hmacsha256 - cryptojs</li> * <li>hmacsha384 - cryptojs</li> * <li>hmacsha512 - cryptojs</li> * </ul> * NOTE: HmacSHA224 and HmacSHA384 issue was fixed since jsrsasign 4.1.4. * Please use 'ext/cryptojs-312-core-fix*.js' instead of 'core.js' of original CryptoJS * to avoid those issue. * @example * var mac = new KJUR.crypto.Mac({alg: "HmacSHA1", prov: "cryptojs", "pass": "pass"}); * mac.updateString('aaa') * var macHex = md.doFinal() */ KJUR.crypto.Mac = function(params) { var mac = null; var pass = null; var algName = null; var provName = null; var algProv = null; this.setAlgAndProvider = function(alg, prov) { if (alg == null) alg = "hmacsha1"; alg = alg.toLowerCase(); if (alg.substr(0, 4) != "hmac") { throw "setAlgAndProvider unsupported HMAC alg: " + alg; } if (prov === undefined) prov = KJUR.crypto.Util.DEFAULTPROVIDER[alg]; this.algProv = alg + "/" + prov; var hashAlg = alg.substr(4); // for cryptojs if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(hashAlg) != -1 && prov == 'cryptojs') { try { var mdObj = eval(KJUR.crypto.Util.CRYPTOJSMESSAGEDIGESTNAME[hashAlg]); this.mac = CryptoJS.algo.HMAC.create(mdObj, this.pass); } catch (ex) { throw "setAlgAndProvider hash alg set fail hashAlg=" + hashAlg + "/" + ex; } this.updateString = function(str) { this.mac.update(str); }; this.updateHex = function(hex) { var wHex = CryptoJS.enc.Hex.parse(hex); this.mac.update(wHex); }; this.doFinal = function() { var hash = this.mac.finalize(); return hash.toString(CryptoJS.enc.Hex); }; this.doFinalString = function(str) { this.updateString(str); return this.doFinal(); }; this.doFinalHex = function(hex) { this.updateHex(hex); return this.doFinal(); }; } }; /** * update digest by specified string * @name updateString * @memberOf KJUR.crypto.Mac * @function * @param {String} str string to update * @description * @example * md.updateString('New York'); */ this.updateString = function(str) { throw "updateString(str) not supported for this alg/prov: " + this.algProv; }; /** * update digest by specified hexadecimal string * @name updateHex * @memberOf KJUR.crypto.Mac * @function * @param {String} hex hexadecimal string to update * @description * @example * md.updateHex('0afe36'); */ this.updateHex = function(hex) { throw "updateHex(hex) not supported for this alg/prov: " + this.algProv; }; /** * completes hash calculation and returns hash result * @name doFinal * @memberOf KJUR.crypto.Mac * @function * @description * @example * md.digest() */ this.doFinal = function() { throw "digest() not supported for this alg/prov: " + this.algProv; }; /** * performs final update on the digest using string, then completes the digest computation * @name doFinalString * @memberOf KJUR.crypto.Mac * @function * @param {String} str string to final update * @description * @example * md.digestString('aaa') */ this.doFinalString = function(str) { throw "digestString(str) not supported for this alg/prov: " + this.algProv; }; /** * performs final update on the digest using hexadecimal string, * then completes the digest computation * @name doFinalHex * @memberOf KJUR.crypto.Mac * @function * @param {String} hex hexadecimal string to final update * @description * @example * md.digestHex('0f2abd') */ this.doFinalHex = function(hex) { throw "digestHex(hex) not supported for this alg/prov: " + this.algProv; }; if (params !== undefined) { if (params['pass'] !== undefined) { this.pass = params['pass']; } if (params['alg'] !== undefined) { this.algName = params['alg']; if (params['prov'] === undefined) this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]; this.setAlgAndProvider(this.algName, this.provName); } } }; /** * Signature class which is very similar to java.security.Signature class * @name KJUR.crypto.Signature * @class Signature class which is very similar to java.security.Signature class * @param {Array} params parameters for constructor * @property {String} state Current state of this signature object whether 'SIGN', 'VERIFY' or null * @description * <br/> * As for params of constructor's argument, it can be specify following attributes: * <ul> * <li>alg - signature algorithm name (ex. {MD5,SHA1,SHA224,SHA256,SHA384,SHA512,RIPEMD160}with{RSA,ECDSA,DSA})</li> * <li>provider - currently 'cryptojs/jsrsa' only</li> * </ul> * <h4>SUPPORTED ALGORITHMS AND PROVIDERS</h4> * This Signature class supports following signature algorithm and provider names: * <ul> * <li>MD5withRSA - cryptojs/jsrsa</li> * <li>SHA1withRSA - cryptojs/jsrsa</li> * <li>SHA224withRSA - cryptojs/jsrsa</li> * <li>SHA256withRSA - cryptojs/jsrsa</li> * <li>SHA384withRSA - cryptojs/jsrsa</li> * <li>SHA512withRSA - cryptojs/jsrsa</li> * <li>RIPEMD160withRSA - cryptojs/jsrsa</li> * <li>MD5withECDSA - cryptojs/jsrsa</li> * <li>SHA1withECDSA - cryptojs/jsrsa</li> * <li>SHA224withECDSA - cryptojs/jsrsa</li> * <li>SHA256withECDSA - cryptojs/jsrsa</li> * <li>SHA384withECDSA - cryptojs/jsrsa</li> * <li>SHA512withECDSA - cryptojs/jsrsa</li> * <li>RIPEMD160withECDSA - cryptojs/jsrsa</li> * <li>MD5withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA1withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA224withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA256withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA384withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA512withRSAandMGF1 - cryptojs/jsrsa</li> * <li>RIPEMD160withRSAandMGF1 - cryptojs/jsrsa</li> * <li>SHA1withDSA - cryptojs/jsrsa</li> * <li>SHA224withDSA - cryptojs/jsrsa</li> * <li>SHA256withDSA - cryptojs/jsrsa</li> * </ul> * Here are supported elliptic cryptographic curve names and their aliases for ECDSA: * <ul> * <li>secp256k1</li> * <li>secp256r1, NIST P-256, P-256, prime256v1</li> * <li>secp384r1, NIST P-384, P-384</li> * </ul> * NOTE1: DSA signing algorithm is also supported since crypto 1.1.5. * <h4>EXAMPLES</h4> * @example * // RSA signature generation * var sig = new KJUR.crypto.Signature({"alg": "SHA1withRSA"}); * sig.init(prvKeyPEM); * sig.updateString('aaa'); * var hSigVal = sig.sign(); * * // DSA signature validation * var sig2 = new KJUR.crypto.Signature({"alg": "SHA1withDSA"}); * sig2.init(certPEM); * sig.updateString('aaa'); * var isValid = sig2.verify(hSigVal); * * // ECDSA signing * var sig = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'}); * sig.init(prvKeyPEM); * sig.updateString('aaa'); * var sigValueHex = sig.sign(); * * // ECDSA verifying * var sig2 = new KJUR.crypto.Signature({'alg':'SHA1withECDSA'}); * sig.init(certPEM); * sig.updateString('aaa'); * var isValid = sig.verify(sigValueHex); */ KJUR.crypto.Signature = function(params) { var prvKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for signing var pubKey = null; // RSAKey/KJUR.crypto.{ECDSA,DSA} object for verifying var md = null; // KJUR.crypto.MessageDigest object var sig = null; var algName = null; var provName = null; var algProvName = null; var mdAlgName = null; var pubkeyAlgName = null; // rsa,ecdsa,rsaandmgf1(=rsapss) var state = null; var pssSaltLen = -1; var initParams = null; var sHashHex = null; // hex hash value for hex var hDigestInfo = null; var hPaddedDigestInfo = null; var hSign = null; this._setAlgNames = function() { if (this.algName.match(/^(.+)with(.+)$/)) { this.mdAlgName = RegExp.$1.toLowerCase(); this.pubkeyAlgName = RegExp.$2.toLowerCase(); } }; this._zeroPaddingOfSignature = function(hex, bitLength) { var s = ""; var nZero = bitLength / 4 - hex.length; for (var i = 0; i < nZero; i++) { s = s + "0"; } return s + hex; }; /** * set signature algorithm and provider * @name setAlgAndProvider * @memberOf KJUR.crypto.Signature * @function * @param {String} alg signature algorithm name * @param {String} prov provider name * @description * @example * md.setAlgAndProvider('SHA1withRSA', 'cryptojs/jsrsa'); */ this.setAlgAndProvider = function(alg, prov) { this._setAlgNames(); if (prov != 'cryptojs/jsrsa') throw "provider not supported: " + prov; if (':md5:sha1:sha224:sha256:sha384:sha512:ripemd160:'.indexOf(this.mdAlgName) != -1) { try { this.md = new KJUR.crypto.MessageDigest({'alg':this.mdAlgName}); } catch (ex) { throw "setAlgAndProvider hash alg set fail alg=" + this.mdAlgName + "/" + ex; } this.init = function(keyparam, pass) { var keyObj = null; try { if (pass === undefined) { keyObj = KEYUTIL.getKey(keyparam); } else { keyObj = KEYUTIL.getKey(keyparam, pass); } } catch (ex) { throw "init failed:" + ex; } if (keyObj.isPrivate === true) { this.prvKey = keyObj; this.state = "SIGN"; } else if (keyObj.isPublic === true) { this.pubKey = keyObj; this.state = "VERIFY"; } else { throw "init failed.:" + keyObj; } }; this.initSign = function(params) { if (typeof params['ecprvhex'] == 'string' && typeof params['eccurvename'] == 'string') { this.ecprvhex = params['ecprvhex']; this.eccurvename = params['eccurvename']; } else { this.prvKey = params; } this.state = "SIGN"; }; this.initVerifyByPublicKey = function(params) { if (typeof params['ecpubhex'] == 'string' && typeof params['eccurvename'] == 'string') { this.ecpubhex = params['ecpubhex']; this.eccurvename = params['eccurvename']; } else if (params instanceof KJUR.crypto.ECDSA) { this.pubKey = params; } else if (params instanceof RSAKey) { this.pubKey = params; } this.state = "VERIFY"; }; this.initVerifyByCertificatePEM = function(certPEM) { var x509 = new X509(); x509.readCertPEM(certPEM); this.pubKey = x509.subjectPublicKeyRSA; this.state = "VERIFY"; }; this.updateString = function(str) { this.md.updateString(str); }; this.updateHex = function(hex) { this.md.updateHex(hex); }; this.sign = function() { this.sHashHex = this.md.digest(); if (typeof this.ecprvhex != "undefined" && typeof this.eccurvename != "undefined") { var ec = new KJUR.crypto.ECDSA({'curve': this.eccurvename}); this.hSign = ec.signHex(this.sHashHex, this.ecprvhex); } else if (this.pubkeyAlgName == "rsaandmgf1") { this.hSign = this.prvKey.signWithMessageHashPSS(this.sHashHex, this.mdAlgName, this.pssSaltLen); } else if (this.pubkeyAlgName == "rsa") { this.hSign = this.prvKey.signWithMessageHash(this.sHashHex, this.mdAlgName); } else if (this.prvKey instanceof KJUR.crypto.ECDSA) { this.hSign = this.prvKey.signWithMessageHash(this.sHashHex); } else if (this.prvKey instanceof KJUR.crypto.DSA) { this.hSign = this.prvKey.signWithMessageHash(this.sHashHex); } else { throw "Signature: unsupported public key alg: " + this.pubkeyAlgName; } return this.hSign; }; this.signString = function(str) { this.updateString(str); return this.sign(); }; this.signHex = function(hex) { this.updateHex(hex); return this.sign(); }; this.verify = function(hSigVal) { this.sHashHex = this.md.digest(); if (typeof this.ecpubhex != "undefined" && typeof this.eccurvename != "undefined") { var ec = new KJUR.crypto.ECDSA({curve: this.eccurvename}); return ec.verifyHex(this.sHashHex, hSigVal, this.ecpubhex); } else if (this.pubkeyAlgName == "rsaandmgf1") { return this.pubKey.verifyWithMessageHashPSS(this.sHashHex, hSigVal, this.mdAlgName, this.pssSaltLen); } else if (this.pubkeyAlgName == "rsa") { return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); } else if (this.pubKey instanceof KJUR.crypto.ECDSA) { return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); } else if (this.pubKey instanceof KJUR.crypto.DSA) { return this.pubKey.verifyWithMessageHash(this.sHashHex, hSigVal); } else { throw "Signature: unsupported public key alg: " + this.pubkeyAlgName; } }; } }; /** * Initialize this object for signing or verifying depends on key * @name init * @memberOf KJUR.crypto.Signature * @function * @param {Object} key specifying public or private key as plain/encrypted PKCS#5/8 PEM file, certificate PEM or {@link RSAKey}, {@link KJUR.crypto.DSA} or {@link KJUR.crypto.ECDSA} object * @param {String} pass (OPTION) passcode for encrypted private key * @since crypto 1.1.3 * @description * This method is very useful initialize method for Signature class since * you just specify key then this method will automatically initialize it * using {@link KEYUTIL.getKey} method. * As for 'key', following argument type are supported: * <h5>signing</h5> * <ul> * <li>PEM formatted PKCS#8 encrypted RSA/ECDSA private key concluding "BEGIN ENCRYPTED PRIVATE KEY"</li> * <li>PEM formatted PKCS#5 encrypted RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" and ",ENCRYPTED"</li> * <li>PEM formatted PKCS#8 plain RSA/ECDSA private key concluding "BEGIN PRIVATE KEY"</li> * <li>PEM formatted PKCS#5 plain RSA/DSA private key concluding "BEGIN RSA/DSA PRIVATE KEY" without ",ENCRYPTED"</li> * <li>RSAKey object of private key</li> * <li>KJUR.crypto.ECDSA object of private key</li> * <li>KJUR.crypto.DSA object of private key</li> * </ul> * <h5>verification</h5> * <ul> * <li>PEM formatted PKCS#8 RSA/EC/DSA public key concluding "BEGIN PUBLIC KEY"</li> * <li>PEM formatted X.509 certificate with RSA/EC/DSA public key concluding * "BEGIN CERTIFICATE", "BEGIN X509 CERTIFICATE" or "BEGIN TRUSTED CERTIFICATE".</li> * <li>RSAKey object of public key</li> * <li>KJUR.crypto.ECDSA object of public key</li> * <li>KJUR.crypto.DSA object of public key</li> * </ul> * @example * sig.init(sCertPEM) */ this.init = function(key, pass) { throw "init(key, pass) not supported for this alg:prov=" + this.algProvName; }; /** * Initialize this object for verifying with a public key * @name initVerifyByPublicKey * @memberOf KJUR.crypto.Signature * @function * @param {Object} param RSAKey object of public key or associative array for ECDSA * @since 1.0.2 * @deprecated from crypto 1.1.5. please use init() method instead. * @description * Public key information will be provided as 'param' parameter and the value will be * following: * <ul> * <li>{@link RSAKey} object for RSA verification</li> * <li>associative array for ECDSA verification * (ex. <code>{'ecpubhex': '041f..', 'eccurvename': 'secp256r1'}</code>) * </li> * </ul> * @example * sig.initVerifyByPublicKey(rsaPrvKey) */ this.initVerifyByPublicKey = function(rsaPubKey) { throw "initVerifyByPublicKey(rsaPubKeyy) not supported for this alg:prov=" + this.algProvName; }; /** * Initialize this object for verifying with a certficate * @name initVerifyByCertificatePEM * @memberOf KJUR.crypto.Signature * @function * @param {String} certPEM PEM formatted string of certificate * @since 1.0.2 * @deprecated from crypto 1.1.5. please use init() method instead. * @description * @example * sig.initVerifyByCertificatePEM(certPEM) */ this.initVerifyByCertificatePEM = function(certPEM) { throw "initVerifyByCertificatePEM(certPEM) not supported for this alg:prov=" + this.algProvName; }; /** * Initialize this object for signing * @name initSign * @memberOf KJUR.crypto.Signature * @function * @param {Object} param RSAKey object of public key or associative array for ECDSA * @deprecated from crypto 1.1.5. please use init() method instead. * @description * Private key information will be provided as 'param' parameter and the value will be * following: * <ul> * <li>{@link RSAKey} object for RSA signing</li> * <li>associative array for ECDSA signing * (ex. <code>{'ecprvhex': '1d3f..', 'eccurvename': 'secp256r1'}</code>)</li> * </ul> * @example * sig.initSign(prvKey) */ this.initSign = function(prvKey) { throw "initSign(prvKey) not supported for this alg:prov=" + this.algProvName; }; /** * Updates the data to be signed or verified by a string * @name updateString * @memberOf KJUR.crypto.Signature * @function * @param {String} str string to use for the update * @description * @example * sig.updateString('aaa') */ this.updateString = function(str) { throw "updateString(str) not supported for this alg:prov=" + this.algProvName; }; /** * Updates the data to be signed or verified by a hexadecimal string * @name updateHex * @memberOf KJUR.crypto.Signature * @function * @param {String} hex hexadecimal string to use for the update * @description * @example * sig.updateHex('1f2f3f') */ this.updateHex = function(hex) { throw "updateHex(hex) not supported for this alg:prov=" + this.algProvName; }; /** * Returns the signature bytes of all data updates as a hexadecimal string * @name sign * @memberOf KJUR.crypto.Signature * @function * @return the signature bytes as a hexadecimal string * @description * @example * var hSigValue = sig.sign() */ this.sign = function() { throw "sign() not supported for this alg:prov=" + this.algProvName; }; /** * performs final update on the sign using string, then returns the signature bytes of all data updates as a hexadecimal string * @name signString * @memberOf KJUR.crypto.Signature * @function * @param {String} str string to final update * @return the signature bytes of a hexadecimal string * @description * @example * var hSigValue = sig.signString('aaa') */ this.signString = function(str) { throw "digestString(str) not supported for this alg:prov=" + this.algProvName; }; /** * performs final update on the sign using hexadecimal string, then returns the signature bytes of all data updates as a hexadecimal string * @name signHex * @memberOf KJUR.crypto.Signature * @function * @param {String} hex hexadecimal string to final update * @return the signature bytes of a hexadecimal string * @description * @example * var hSigValue = sig.signHex('1fdc33') */ this.signHex = function(hex) { throw "digestHex(hex) not supported for this alg:prov=" + this.algProvName; }; /** * verifies the passed-in signature. * @name verify * @memberOf KJUR.crypto.Signature * @function * @param {String} str string to final update * @return {Boolean} true if the signature was verified, otherwise false * @description * @example * var isValid = sig.verify('1fbcefdca4823a7(snip)') */ this.verify = function(hSigVal) { throw "verify(hSigVal) not supported for this alg:prov=" + this.algProvName; }; this.initParams = params; if (params !== undefined) { if (params['alg'] !== undefined) { this.algName = params['alg']; if (params['prov'] === undefined) { this.provName = KJUR.crypto.Util.DEFAULTPROVIDER[this.algName]; } else { this.provName = params['prov']; } this.algProvName = this.algName + ":" + this.provName; this.setAlgAndProvider(this.algName, this.provName); this._setAlgNames(); } if (params['psssaltlen'] !== undefined) this.pssSaltLen = params['psssaltlen']; if (params['prvkeypem'] !== undefined) { if (params['prvkeypas'] !== undefined) { throw "both prvkeypem and prvkeypas parameters not supported"; } else { try { var prvKey = new RSAKey(); prvKey.readPrivateKeyFromPEMString(params['prvkeypem']); this.initSign(prvKey); } catch (ex) { throw "fatal error to load pem private key: " + ex; } } } } }; /** * static object for cryptographic function utilities * @name KJUR.crypto.OID * @class static object for cryptography related OIDs * @property {Array} oidhex2name key value of hexadecimal OID and its name * (ex. '2a8648ce3d030107' and 'secp256r1') * @since crypto 1.1.3 * @description */ KJUR.crypto.OID = new function() { this.oidhex2name = { '2a864886f70d010101': 'rsaEncryption', '2a8648ce3d0201': 'ecPublicKey', '2a8648ce380401': 'dsa', '2a8648ce3d030107': 'secp256r1', '2b8104001f': 'secp192k1', '2b81040021': 'secp224r1', '2b8104000a': 'secp256k1', '2b81040023': 'secp521r1', '2b81040022': 'secp384r1', '2a8648ce380403': 'SHA1withDSA', // 1.2.840.10040.4.3 '608648016503040301': 'SHA224withDSA', // 2.16.840.1.101.3.4.3.1 '608648016503040302': 'SHA256withDSA', // 2.16.840.1.101.3.4.3.2 }; }; // ./lib/jsrsasign/ext/cryptojs-312-core-fix.js /*! CryptoJS v3.1.2 core-fix.js * code.google.com/p/crypto-js * (c) 2009-2013 by Jeff Mott. All rights reserved. * code.google.com/p/crypto-js/wiki/License * THIS IS FIX of 'core.js' to fix Hmac issue. * https://code.google.com/p/crypto-js/issues/detail?id=84 * https://crypto-js.googlecode.com/svn-history/r667/branches/3.x/src/core.js */ /** * CryptoJS core components. */ var CryptoJS = CryptoJS || (function (Math, undefined) { /** * CryptoJS namespace. */ var C = {}; /** * Library namespace. */ var C_lib = C.lib = {}; /** * Base object for prototypal inheritance. */ var Base = C_lib.Base = (function () { function F() {} return { /** * Creates a new object that inherits from this object. * * @param {Object} overrides Properties to copy into the new object. * * @return {Object} The new object. * * @static * * @example * * var MyType = CryptoJS.lib.Base.extend({ * field: 'value', * * method: function () { * } * }); */ extend: function (overrides) { // Spawn F.prototype = this; var subtype = new F(); // Augment if (overrides) { subtype.mixIn(overrides); } // Create default initializer if (!subtype.hasOwnProperty('init')) { subtype.init = function () { subtype.$super.init.apply(this, arguments); }; } // Initializer's prototype is the subtype object subtype.init.prototype = subtype; // Reference supertype subtype.$super = this; return subtype; }, /** * Extends this object and runs the init method. * Arguments to create() will be passed to init(). * * @return {Object} The new object. * * @static * * @example * * var instance = MyType.create(); */ create: function () { var instance = this.extend(); instance.init.apply(instance, arguments); return instance; }, /** * Initializes a newly created object. * Override this method to add some logic when your objects are created. * * @example * * var MyType = CryptoJS.lib.Base.extend({ * init: function () { * // ... * } * }); */ init: function () { }, /** * Copies properties into this object. * * @param {Object} properties The properties to mix in. * * @example * * MyType.mixIn({ * field: 'value' * }); */ mixIn: function (properties) { for (var propertyName in properties) { if (properties.hasOwnProperty(propertyName)) { this[propertyName] = properties[propertyName]; } } // IE won't copy toString using the loop above if (properties.hasOwnProperty('toString')) { this.toString = properties.toString; } }, /** * Creates a copy of