123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807 |
- ;(function (root, factory) {
- if (typeof exports === "object") {
-
- module.exports = exports = factory();
- }
- else if (typeof define === "function" && define.amd) {
-
- define([], factory);
- }
- else {
-
- root.CryptoJS = factory();
- }
- }(this, function () {
-
-
- var CryptoJS = CryptoJS || (function (Math, undefined) {
- var crypto;
-
- if (typeof window !== 'undefined' && window.crypto) {
- crypto = window.crypto;
- }
-
- if (typeof self !== 'undefined' && self.crypto) {
- crypto = self.crypto;
- }
-
- if (typeof globalThis !== 'undefined' && globalThis.crypto) {
- crypto = globalThis.crypto;
- }
-
- if (!crypto && typeof window !== 'undefined' && window.msCrypto) {
- crypto = window.msCrypto;
- }
-
- if (!crypto && typeof global !== 'undefined' && global.crypto) {
- crypto = global.crypto;
- }
-
- if (!crypto && typeof require === 'function') {
- try {
- crypto = require('crypto');
- } catch (err) {}
- }
-
- var cryptoSecureRandomInt = function () {
- if (crypto) {
-
- if (typeof crypto.getRandomValues === 'function') {
- try {
- return crypto.getRandomValues(new Uint32Array(1))[0];
- } catch (err) {}
- }
-
- if (typeof crypto.randomBytes === 'function') {
- try {
- return crypto.randomBytes(4).readInt32LE();
- } catch (err) {}
- }
- }
- throw new Error('Native crypto module could not be used to get secure random number.');
- };
-
- var create = Object.create || (function () {
- function F() {}
- return function (obj) {
- var subtype;
- F.prototype = obj;
- subtype = new F();
- F.prototype = null;
- return subtype;
- };
- }());
-
- var C = {};
-
- var C_lib = C.lib = {};
-
- var Base = C_lib.Base = (function () {
- return {
-
- extend: function (overrides) {
-
- var subtype = create(this);
-
- if (overrides) {
- subtype.mixIn(overrides);
- }
-
- if (!subtype.hasOwnProperty('init') || this.init === subtype.init) {
- subtype.init = function () {
- subtype.$super.init.apply(this, arguments);
- };
- }
-
- subtype.init.prototype = subtype;
-
- subtype.$super = this;
- return subtype;
- },
-
- create: function () {
- var instance = this.extend();
- instance.init.apply(instance, arguments);
- return instance;
- },
-
- init: function () {
- },
-
- mixIn: function (properties) {
- for (var propertyName in properties) {
- if (properties.hasOwnProperty(propertyName)) {
- this[propertyName] = properties[propertyName];
- }
- }
-
- if (properties.hasOwnProperty('toString')) {
- this.toString = properties.toString;
- }
- },
-
- clone: function () {
- return this.init.prototype.extend(this);
- }
- };
- }());
-
- var WordArray = C_lib.WordArray = Base.extend({
-
- init: function (words, sigBytes) {
- words = this.words = words || [];
- if (sigBytes != undefined) {
- this.sigBytes = sigBytes;
- } else {
- this.sigBytes = words.length * 4;
- }
- },
-
- toString: function (encoder) {
- return (encoder || Hex).stringify(this);
- },
-
- concat: function (wordArray) {
-
- var thisWords = this.words;
- var thatWords = wordArray.words;
- var thisSigBytes = this.sigBytes;
- var thatSigBytes = wordArray.sigBytes;
-
- this.clamp();
-
- if (thisSigBytes % 4) {
-
- for (var i = 0; i < thatSigBytes; i++) {
- var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
- }
- } else {
-
- for (var j = 0; j < thatSigBytes; j += 4) {
- thisWords[(thisSigBytes + j) >>> 2] = thatWords[j >>> 2];
- }
- }
- this.sigBytes += thatSigBytes;
-
- return this;
- },
-
- clamp: function () {
-
- var words = this.words;
- var sigBytes = this.sigBytes;
-
- words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
- words.length = Math.ceil(sigBytes / 4);
- },
-
- clone: function () {
- var clone = Base.clone.call(this);
- clone.words = this.words.slice(0);
- return clone;
- },
-
- random: function (nBytes) {
- var words = [];
- for (var i = 0; i < nBytes; i += 4) {
- words.push(cryptoSecureRandomInt());
- }
- return new WordArray.init(words, nBytes);
- }
- });
-
- var C_enc = C.enc = {};
-
- var Hex = C_enc.Hex = {
-
- stringify: function (wordArray) {
-
- var words = wordArray.words;
- var sigBytes = wordArray.sigBytes;
-
- var hexChars = [];
- for (var i = 0; i < sigBytes; i++) {
- var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- hexChars.push((bite >>> 4).toString(16));
- hexChars.push((bite & 0x0f).toString(16));
- }
- return hexChars.join('');
- },
-
- parse: function (hexStr) {
-
- var hexStrLength = hexStr.length;
-
- var words = [];
- for (var i = 0; i < hexStrLength; i += 2) {
- words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
- }
- return new WordArray.init(words, hexStrLength / 2);
- }
- };
-
- var Latin1 = C_enc.Latin1 = {
-
- stringify: function (wordArray) {
-
- var words = wordArray.words;
- var sigBytes = wordArray.sigBytes;
-
- var latin1Chars = [];
- for (var i = 0; i < sigBytes; i++) {
- var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
- latin1Chars.push(String.fromCharCode(bite));
- }
- return latin1Chars.join('');
- },
-
- parse: function (latin1Str) {
-
- var latin1StrLength = latin1Str.length;
-
- var words = [];
- for (var i = 0; i < latin1StrLength; i++) {
- words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
- }
- return new WordArray.init(words, latin1StrLength);
- }
- };
-
- var Utf8 = C_enc.Utf8 = {
-
- stringify: function (wordArray) {
- try {
- return decodeURIComponent(escape(Latin1.stringify(wordArray)));
- } catch (e) {
- throw new Error('Malformed UTF-8 data');
- }
- },
-
- parse: function (utf8Str) {
- return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
- }
- };
-
- var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
-
- reset: function () {
-
- this._data = new WordArray.init();
- this._nDataBytes = 0;
- },
-
- _append: function (data) {
-
- if (typeof data == 'string') {
- data = Utf8.parse(data);
- }
-
- this._data.concat(data);
- this._nDataBytes += data.sigBytes;
- },
-
- _process: function (doFlush) {
- var processedWords;
-
- var data = this._data;
- var dataWords = data.words;
- var dataSigBytes = data.sigBytes;
- var blockSize = this.blockSize;
- var blockSizeBytes = blockSize * 4;
-
- var nBlocksReady = dataSigBytes / blockSizeBytes;
- if (doFlush) {
-
- nBlocksReady = Math.ceil(nBlocksReady);
- } else {
-
-
- nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
- }
-
- var nWordsReady = nBlocksReady * blockSize;
-
- var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
-
- if (nWordsReady) {
- for (var offset = 0; offset < nWordsReady; offset += blockSize) {
-
- this._doProcessBlock(dataWords, offset);
- }
-
- processedWords = dataWords.splice(0, nWordsReady);
- data.sigBytes -= nBytesReady;
- }
-
- return new WordArray.init(processedWords, nBytesReady);
- },
-
- clone: function () {
- var clone = Base.clone.call(this);
- clone._data = this._data.clone();
- return clone;
- },
- _minBufferSize: 0
- });
-
- var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
-
- cfg: Base.extend(),
-
- init: function (cfg) {
-
- this.cfg = this.cfg.extend(cfg);
-
- this.reset();
- },
-
- reset: function () {
-
- BufferedBlockAlgorithm.reset.call(this);
-
- this._doReset();
- },
-
- update: function (messageUpdate) {
-
- this._append(messageUpdate);
-
- this._process();
-
- return this;
- },
-
- finalize: function (messageUpdate) {
-
- if (messageUpdate) {
- this._append(messageUpdate);
- }
-
- var hash = this._doFinalize();
- return hash;
- },
- blockSize: 512/32,
-
- _createHelper: function (hasher) {
- return function (message, cfg) {
- return new hasher.init(cfg).finalize(message);
- };
- },
-
- _createHmacHelper: function (hasher) {
- return function (message, key) {
- return new C_algo.HMAC.init(hasher, key).finalize(message);
- };
- }
- });
-
- var C_algo = C.algo = {};
- return C;
- }(Math));
- return CryptoJS;
- }));
|