1 |
- (function(){function n(g){var k=g.jsustoolkitErrCode=g.jsustoolkitErrCode||{},d=g.pkcs5=g.pkcs5||{},b=g.asn1,h=g.pki=g.pki||{};d.pbe={};var m={name:"PBES1Algorithms.params",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"PBES1Algorithms.params.salt",tagClass:b.Class.UNIVERSAL,type:b.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES1Algorithms.params.iterationCount",tagClass:b.Class.UNIVERSAL,type:b.Type.INTEGER,onstructed:!0,capture:"kdfIterationCount"}]},n={name:"PBES2Algorithms",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.keyDerivationFunc.oid",tagClass:b.Class.UNIVERSAL,type:b.Type.OID,constructed:!1,capture:"kdfOid"},{name:"PBES2Algorithms.params",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.params.salt",tagClass:b.Class.UNIVERSAL,type:b.Type.OCTETSTRING,constructed:!1,capture:"kdfSalt"},{name:"PBES2Algorithms.params.iterationCount",tagClass:b.Class.UNIVERSAL,type:b.Type.INTEGER,onstructed:!0,capture:"kdfIterationCount"}]}]},{name:"PBES2Algorithms.encryptionScheme",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"PBES2Algorithms.encryptionScheme.oid",tagClass:b.Class.UNIVERSAL,type:b.Type.OID,constructed:!1,capture:"encOid"},{name:"PBES2Algorithms.encryptionScheme.iv",tagClass:b.Class.UNIVERSAL,type:b.Type.OCTETSTRING,constructed:!1,capture:"encIv"}]}]},p={name:"pkcs-12PbeParams",tagClass:b.Class.UNIVERSAL,type:b.Type.SEQUENCE,constructed:!0,value:[{name:"pkcs-12PbeParams.salt",tagClass:b.Class.UNIVERSAL,type:b.Type.OCTETSTRING,constructed:!1,capture:"salt"},{name:"pkcs-12PbeParams.iterations",tagClass:b.Class.UNIVERSAL,type:b.Type.INTEGER,constructed:!1,capture:"iterations"}]};d.pbkdf1=function(a,f,l,e,c){if(null==a||"undefined"==typeof a)throw{code:"111001",message:k["111001"]};if(null==f||"undefined"==typeof f)throw{code:"111002",message:k["111002"]};if(null==l||"undefined"==typeof l)throw{code:"111003",message:k["111003"]};if(null==e||"undefined"==typeof e)throw{code:"111004",message:k["111004"]};if("undefined"===typeof c||null===c)c=g.md.sha1.create();if(e>4294967295*c.digestLength)throw{code:"111005",message:k["111005"]};c.start();c.update(a);a=f;for(f=1;f<=l;++f)1<f&&c.start(),c.update(a),a=c.digest().getBytes();return a};d.pbe.getCipherForPBES1=function(a,f,l){if(null==a||"undefined"==typeof a)throw{code:"111006",message:k["111006"]};if(null==f||"undefined"==typeof f)throw{code:"111007",message:k["111007"]};if(null==l||"undefined"==typeof l)throw{code:"111008",message:k["111008"]};var e={},c=[];if(!b.validate(f,m,e,c))throw{code:"111009",message:k["111009"],errors:c};c=e.kdfSalt;var q=g.util.createBuffer(e.kdfIterationCount);q=q.getInt(q.length()<<3);e=20;a===h.oids["aes128-CBC"]?e=16:a===h.oids["aes192-CBC"]?e=24:a===h.oids["aes256-CBC"]?e=32:a===h.oids.seedCBCWithSHA1?e=16:a===h.oids["seed-CBC"]&&(e=16,null==c&&(c="123456789012345"));f=g.md.sha1.create();c=g.pkcs5.pbkdf1(l,c,q,f.digestLength,f);l=c.slice(0,e);a===h.oids["seed-CBC"]?e="123456789012345":(c=c.slice(e,f.digestLength),f.start(),f.update(c),c=f.digest().getBytes(),e=c.slice(0,e));a=a===h.oids.seedCBCWithSHA1||a===h.oids["seed-CBC"]?g.seed.createDecryptionCipher(l):g.aes.createDecryptionCipher(l);a.start(e);return a};d.pbkdf2=function(a,f,l,e,c){if(null==a||"undefined"==typeof a)throw{code:"111001",message:k["111001"]};if(null==f||"undefined"==typeof f)throw{code:"111002",message:k["111002"]};if(null==l||"undefined"==typeof l)throw{code:"111003",message:k["111003"]};if(null==e||"undefined"==typeof e)throw{code:"111004",message:k["111004"]};if("undefined"===typeof c||null===c)c=g.md.sha1.create();var b=c.digestLength;if(e>4294967295*b)throw{code:"111005",message:k["111005"]};var h=Math.ceil(e/b);e-=(h-1)*b;var d=g.hmac.create();d.start(c,a);a="";for(var m,n=1;n<=h;++n){d.update(f);d.update(g.util.int32ToBytes(n));c=m=d.digest().getBytes();for(var p=2;p<=l;++p)d.start(null,null),d.update(m),m=d.digest().getBytes(),c=g.util.xorBytes(c,m,b);a+=n<h?c:c.substr(0,e)}return a};d.pbe.getCipherForPBES2=function(a,f,l){if(null==a||"undefined"==typeof a)throw{code:"111006",message:k["111006"]};if(null==f||"undefined"==typeof f)throw{code:"111007",message:k["111007"]};if(null==l||"undefined"==typeof l)throw{code:"111008",message:k["111008"]};var e={};a=[];if(!b.validate(f,n,e,a))throw{code:"111009",message:k["111009"],errors:a};a=b.derToOid(e.kdfOid);if(a!==h.oids.pkcs5PBKDF2)throw{code:"111010",message:k["111010"]+"(oid : "+a+")"};a=b.derToOid(e.encOid);if(a!==h.oids["aes128-CBC"]&&a!==h.oids["aes192-CBC"]&&a!==h.oids["aes256-CBC"]&&a!==h.oids["seed-CBC"])throw{code:"111011",message:k["111011"]+"(oid : "+a+")"};f=e.kdfSalt;var c=g.util.createBuffer(e.kdfIterationCount);c=c.getInt(c.length()<<3);var d=0;a===h.oids["aes128-CBC"]?d=16:a===h.oids["aes192-CBC"]?d=24:a===h.oids["aes256-CBC"]?d=32:a===h.oids["seed-CBC"]&&(d=16);l=g.pkcs5.pbkdf2(l,f,c,d);e=e.encIv;a=a===h.oids["seed-CBC"]?g.seed.createDecryptionCipher(l):g.aes.createDecryptionCipher(l);a.start(e);return a};d.pbe.getCipherForPKCS12PBE=function(a,f,l){if(null==a||"undefined"==typeof a)throw{code:"111012",message:k["111012"]};if(null==f||"undefined"==typeof f)throw{code:"111013",message:k["111013"]};if(null==l||"undefined"==typeof l)throw{code:"111014",message:k["111014"]};var e={},c=[];if(!b.validate(f,p,e,c))throw{code:"111015",message:k["111015"],errors:c};f=g.util.createBuffer(e.salt);e=g.util.createBuffer(e.iterations);e=e.getInt(e.length()<<3);switch(a){case h.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:var d=24;c=8;a=g.des.startDecrypting;break;case h.oids["pbewithSHAAnd40BitRC2-CBC"]:d=5;c=8;a=function(a,c){a=g.rc2.createDecryptionCipher(a,40);a.start(c,null);return a};break;case h.oids.seedCBCWithSHA1:c=d=16;a=g.seed.startDecrypting;break;default:throw{code:"1110133",message:k["111033"]+"(oid : "+a+")"};}d=g.pkcs12.generateKey(l,f,1,e,d);l=g.pkcs12.generateKey(l,f,2,e,c);return a(d,l)};d.pbe.setCipherForPKCS12PBE=function(a,f,d){var e=g.util.createBuffer(f.salt);f=f.count;switch(a){case h.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:var c=24;var b=8;a=g.des.startEncrypting;break;case h.oids.seedCBCWithSHA1:b=c=16;a=g.seed.startEncrypting;break;default:throw{code:"1110116",message:k["111016"]+"(oid : "+a+")"};}c=g.pkcs12.generateKey(d,e,1,f,c);d=g.pkcs12.generateKey(d,e,2,f,b);return a(c,d)};d.pbe.getCipher=function(a,f,b){switch(a){case h.oids.seedCBCWithSHA1:return d.pbe.getCipherForPBES1(a,f,b);case h.oids.pkcs5PBES2:return d.pbe.getCipherForPBES2(a,f,b);case h.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case h.oids["pbewithSHAAnd40BitRC2-CBC"]:return d.pbe.getCipherForPKCS12PBE(a,f,b);default:throw{code:"1110117",message:k["111017"]+"(oid : "+a+")"};}};d.pbe.setCipher=function(a,b,g){switch(a){case h.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]:case h.oids["pbewithSHAAnd40BitRC2-CBC"]:return d.pbe.setCipherForPKCS12PBE(a,b,g);default:throw{code:"1110118",message:k["111018"]+"(oid : "+a+")"};}}}var p=["./hmac","./md","./util","./jsustoolkitErrCode"],m=null;"function"!==typeof define&&("object"===typeof module&&module.exports?m=function(g,k){k(require,module)}:(crosscert=window.crosscert=window.crosscert||{},n(crosscert)));(m||"function"===typeof define)&&(m||define)(["require","module"].concat(p),function(g,k){k.exports=function(d){var b=p.map(function(b){return g(b)}).concat(n);d=d||{};d.defined=d.defined||{};if(d.defined.pkcs5)return d.pkcs5;d.defined.pkcs5=!0;for(var h=0;h<b.length;++h)b[h](d);return d.pkcs5}})})();
|