chunk-MIVSMGMR.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. import {
  2. require_core
  3. } from "./chunk-4NTX3REN.js";
  4. import {
  5. __commonJS
  6. } from "./chunk-2LSFTFF7.js";
  7. // node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/sha1.js
  8. var require_sha1 = __commonJS({
  9. "node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/sha1.js"(exports, module) {
  10. (function(root, factory) {
  11. if (typeof exports === "object") {
  12. module.exports = exports = factory(require_core());
  13. } else if (typeof define === "function" && define.amd) {
  14. define(["./core"], factory);
  15. } else {
  16. factory(root.CryptoJS);
  17. }
  18. })(exports, function(CryptoJS) {
  19. (function() {
  20. var C = CryptoJS;
  21. var C_lib = C.lib;
  22. var WordArray = C_lib.WordArray;
  23. var Hasher = C_lib.Hasher;
  24. var C_algo = C.algo;
  25. var W = [];
  26. var SHA1 = C_algo.SHA1 = Hasher.extend({
  27. _doReset: function() {
  28. this._hash = new WordArray.init([
  29. 1732584193,
  30. 4023233417,
  31. 2562383102,
  32. 271733878,
  33. 3285377520
  34. ]);
  35. },
  36. _doProcessBlock: function(M, offset) {
  37. var H = this._hash.words;
  38. var a = H[0];
  39. var b = H[1];
  40. var c = H[2];
  41. var d = H[3];
  42. var e = H[4];
  43. for (var i = 0; i < 80; i++) {
  44. if (i < 16) {
  45. W[i] = M[offset + i] | 0;
  46. } else {
  47. var n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
  48. W[i] = n << 1 | n >>> 31;
  49. }
  50. var t = (a << 5 | a >>> 27) + e + W[i];
  51. if (i < 20) {
  52. t += (b & c | ~b & d) + 1518500249;
  53. } else if (i < 40) {
  54. t += (b ^ c ^ d) + 1859775393;
  55. } else if (i < 60) {
  56. t += (b & c | b & d | c & d) - 1894007588;
  57. } else {
  58. t += (b ^ c ^ d) - 899497514;
  59. }
  60. e = d;
  61. d = c;
  62. c = b << 30 | b >>> 2;
  63. b = a;
  64. a = t;
  65. }
  66. H[0] = H[0] + a | 0;
  67. H[1] = H[1] + b | 0;
  68. H[2] = H[2] + c | 0;
  69. H[3] = H[3] + d | 0;
  70. H[4] = H[4] + e | 0;
  71. },
  72. _doFinalize: function() {
  73. var data = this._data;
  74. var dataWords = data.words;
  75. var nBitsTotal = this._nDataBytes * 8;
  76. var nBitsLeft = data.sigBytes * 8;
  77. dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
  78. dataWords[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
  79. dataWords[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
  80. data.sigBytes = dataWords.length * 4;
  81. this._process();
  82. return this._hash;
  83. },
  84. clone: function() {
  85. var clone = Hasher.clone.call(this);
  86. clone._hash = this._hash.clone();
  87. return clone;
  88. }
  89. });
  90. C.SHA1 = Hasher._createHelper(SHA1);
  91. C.HmacSHA1 = Hasher._createHmacHelper(SHA1);
  92. })();
  93. return CryptoJS.SHA1;
  94. });
  95. }
  96. });
  97. // node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/hmac.js
  98. var require_hmac = __commonJS({
  99. "node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/hmac.js"(exports, module) {
  100. (function(root, factory) {
  101. if (typeof exports === "object") {
  102. module.exports = exports = factory(require_core());
  103. } else if (typeof define === "function" && define.amd) {
  104. define(["./core"], factory);
  105. } else {
  106. factory(root.CryptoJS);
  107. }
  108. })(exports, function(CryptoJS) {
  109. (function() {
  110. var C = CryptoJS;
  111. var C_lib = C.lib;
  112. var Base = C_lib.Base;
  113. var C_enc = C.enc;
  114. var Utf8 = C_enc.Utf8;
  115. var C_algo = C.algo;
  116. var HMAC = C_algo.HMAC = Base.extend({
  117. /**
  118. * Initializes a newly created HMAC.
  119. *
  120. * @param {Hasher} hasher The hash algorithm to use.
  121. * @param {WordArray|string} key The secret key.
  122. *
  123. * @example
  124. *
  125. * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
  126. */
  127. init: function(hasher, key) {
  128. hasher = this._hasher = new hasher.init();
  129. if (typeof key == "string") {
  130. key = Utf8.parse(key);
  131. }
  132. var hasherBlockSize = hasher.blockSize;
  133. var hasherBlockSizeBytes = hasherBlockSize * 4;
  134. if (key.sigBytes > hasherBlockSizeBytes) {
  135. key = hasher.finalize(key);
  136. }
  137. key.clamp();
  138. var oKey = this._oKey = key.clone();
  139. var iKey = this._iKey = key.clone();
  140. var oKeyWords = oKey.words;
  141. var iKeyWords = iKey.words;
  142. for (var i = 0; i < hasherBlockSize; i++) {
  143. oKeyWords[i] ^= 1549556828;
  144. iKeyWords[i] ^= 909522486;
  145. }
  146. oKey.sigBytes = iKey.sigBytes = hasherBlockSizeBytes;
  147. this.reset();
  148. },
  149. /**
  150. * Resets this HMAC to its initial state.
  151. *
  152. * @example
  153. *
  154. * hmacHasher.reset();
  155. */
  156. reset: function() {
  157. var hasher = this._hasher;
  158. hasher.reset();
  159. hasher.update(this._iKey);
  160. },
  161. /**
  162. * Updates this HMAC with a message.
  163. *
  164. * @param {WordArray|string} messageUpdate The message to append.
  165. *
  166. * @return {HMAC} This HMAC instance.
  167. *
  168. * @example
  169. *
  170. * hmacHasher.update('message');
  171. * hmacHasher.update(wordArray);
  172. */
  173. update: function(messageUpdate) {
  174. this._hasher.update(messageUpdate);
  175. return this;
  176. },
  177. /**
  178. * Finalizes the HMAC computation.
  179. * Note that the finalize operation is effectively a destructive, read-once operation.
  180. *
  181. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  182. *
  183. * @return {WordArray} The HMAC.
  184. *
  185. * @example
  186. *
  187. * var hmac = hmacHasher.finalize();
  188. * var hmac = hmacHasher.finalize('message');
  189. * var hmac = hmacHasher.finalize(wordArray);
  190. */
  191. finalize: function(messageUpdate) {
  192. var hasher = this._hasher;
  193. var innerHash = hasher.finalize(messageUpdate);
  194. hasher.reset();
  195. var hmac = hasher.finalize(this._oKey.clone().concat(innerHash));
  196. return hmac;
  197. }
  198. });
  199. })();
  200. });
  201. }
  202. });
  203. // node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/evpkdf.js
  204. var require_evpkdf = __commonJS({
  205. "node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/evpkdf.js"(exports, module) {
  206. (function(root, factory, undef) {
  207. if (typeof exports === "object") {
  208. module.exports = exports = factory(require_core(), require_sha1(), require_hmac());
  209. } else if (typeof define === "function" && define.amd) {
  210. define(["./core", "./sha1", "./hmac"], factory);
  211. } else {
  212. factory(root.CryptoJS);
  213. }
  214. })(exports, function(CryptoJS) {
  215. (function() {
  216. var C = CryptoJS;
  217. var C_lib = C.lib;
  218. var Base = C_lib.Base;
  219. var WordArray = C_lib.WordArray;
  220. var C_algo = C.algo;
  221. var MD5 = C_algo.MD5;
  222. var EvpKDF = C_algo.EvpKDF = Base.extend({
  223. /**
  224. * Configuration options.
  225. *
  226. * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
  227. * @property {Hasher} hasher The hash algorithm to use. Default: MD5
  228. * @property {number} iterations The number of iterations to perform. Default: 1
  229. */
  230. cfg: Base.extend({
  231. keySize: 128 / 32,
  232. hasher: MD5,
  233. iterations: 1
  234. }),
  235. /**
  236. * Initializes a newly created key derivation function.
  237. *
  238. * @param {Object} cfg (Optional) The configuration options to use for the derivation.
  239. *
  240. * @example
  241. *
  242. * var kdf = CryptoJS.algo.EvpKDF.create();
  243. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
  244. * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
  245. */
  246. init: function(cfg) {
  247. this.cfg = this.cfg.extend(cfg);
  248. },
  249. /**
  250. * Derives a key from a password.
  251. *
  252. * @param {WordArray|string} password The password.
  253. * @param {WordArray|string} salt A salt.
  254. *
  255. * @return {WordArray} The derived key.
  256. *
  257. * @example
  258. *
  259. * var key = kdf.compute(password, salt);
  260. */
  261. compute: function(password, salt) {
  262. var block;
  263. var cfg = this.cfg;
  264. var hasher = cfg.hasher.create();
  265. var derivedKey = WordArray.create();
  266. var derivedKeyWords = derivedKey.words;
  267. var keySize = cfg.keySize;
  268. var iterations = cfg.iterations;
  269. while (derivedKeyWords.length < keySize) {
  270. if (block) {
  271. hasher.update(block);
  272. }
  273. block = hasher.update(password).finalize(salt);
  274. hasher.reset();
  275. for (var i = 1; i < iterations; i++) {
  276. block = hasher.finalize(block);
  277. hasher.reset();
  278. }
  279. derivedKey.concat(block);
  280. }
  281. derivedKey.sigBytes = keySize * 4;
  282. return derivedKey;
  283. }
  284. });
  285. C.EvpKDF = function(password, salt, cfg) {
  286. return EvpKDF.create(cfg).compute(password, salt);
  287. };
  288. })();
  289. return CryptoJS.EvpKDF;
  290. });
  291. }
  292. });
  293. // node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/cipher-core.js
  294. var require_cipher_core = __commonJS({
  295. "node_modules/.pnpm/crypto-js@4.1.1/node_modules/crypto-js/cipher-core.js"(exports, module) {
  296. (function(root, factory, undef) {
  297. if (typeof exports === "object") {
  298. module.exports = exports = factory(require_core(), require_evpkdf());
  299. } else if (typeof define === "function" && define.amd) {
  300. define(["./core", "./evpkdf"], factory);
  301. } else {
  302. factory(root.CryptoJS);
  303. }
  304. })(exports, function(CryptoJS) {
  305. CryptoJS.lib.Cipher || function(undefined) {
  306. var C = CryptoJS;
  307. var C_lib = C.lib;
  308. var Base = C_lib.Base;
  309. var WordArray = C_lib.WordArray;
  310. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm;
  311. var C_enc = C.enc;
  312. var Utf8 = C_enc.Utf8;
  313. var Base64 = C_enc.Base64;
  314. var C_algo = C.algo;
  315. var EvpKDF = C_algo.EvpKDF;
  316. var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({
  317. /**
  318. * Configuration options.
  319. *
  320. * @property {WordArray} iv The IV to use for this operation.
  321. */
  322. cfg: Base.extend(),
  323. /**
  324. * Creates this cipher in encryption mode.
  325. *
  326. * @param {WordArray} key The key.
  327. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  328. *
  329. * @return {Cipher} A cipher instance.
  330. *
  331. * @static
  332. *
  333. * @example
  334. *
  335. * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
  336. */
  337. createEncryptor: function(key, cfg) {
  338. return this.create(this._ENC_XFORM_MODE, key, cfg);
  339. },
  340. /**
  341. * Creates this cipher in decryption mode.
  342. *
  343. * @param {WordArray} key The key.
  344. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  345. *
  346. * @return {Cipher} A cipher instance.
  347. *
  348. * @static
  349. *
  350. * @example
  351. *
  352. * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
  353. */
  354. createDecryptor: function(key, cfg) {
  355. return this.create(this._DEC_XFORM_MODE, key, cfg);
  356. },
  357. /**
  358. * Initializes a newly created cipher.
  359. *
  360. * @param {number} xformMode Either the encryption or decryption transormation mode constant.
  361. * @param {WordArray} key The key.
  362. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  363. *
  364. * @example
  365. *
  366. * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
  367. */
  368. init: function(xformMode, key, cfg) {
  369. this.cfg = this.cfg.extend(cfg);
  370. this._xformMode = xformMode;
  371. this._key = key;
  372. this.reset();
  373. },
  374. /**
  375. * Resets this cipher to its initial state.
  376. *
  377. * @example
  378. *
  379. * cipher.reset();
  380. */
  381. reset: function() {
  382. BufferedBlockAlgorithm.reset.call(this);
  383. this._doReset();
  384. },
  385. /**
  386. * Adds data to be encrypted or decrypted.
  387. *
  388. * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
  389. *
  390. * @return {WordArray} The data after processing.
  391. *
  392. * @example
  393. *
  394. * var encrypted = cipher.process('data');
  395. * var encrypted = cipher.process(wordArray);
  396. */
  397. process: function(dataUpdate) {
  398. this._append(dataUpdate);
  399. return this._process();
  400. },
  401. /**
  402. * Finalizes the encryption or decryption process.
  403. * Note that the finalize operation is effectively a destructive, read-once operation.
  404. *
  405. * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
  406. *
  407. * @return {WordArray} The data after final processing.
  408. *
  409. * @example
  410. *
  411. * var encrypted = cipher.finalize();
  412. * var encrypted = cipher.finalize('data');
  413. * var encrypted = cipher.finalize(wordArray);
  414. */
  415. finalize: function(dataUpdate) {
  416. if (dataUpdate) {
  417. this._append(dataUpdate);
  418. }
  419. var finalProcessedData = this._doFinalize();
  420. return finalProcessedData;
  421. },
  422. keySize: 128 / 32,
  423. ivSize: 128 / 32,
  424. _ENC_XFORM_MODE: 1,
  425. _DEC_XFORM_MODE: 2,
  426. /**
  427. * Creates shortcut functions to a cipher's object interface.
  428. *
  429. * @param {Cipher} cipher The cipher to create a helper for.
  430. *
  431. * @return {Object} An object with encrypt and decrypt shortcut functions.
  432. *
  433. * @static
  434. *
  435. * @example
  436. *
  437. * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
  438. */
  439. _createHelper: function() {
  440. function selectCipherStrategy(key) {
  441. if (typeof key == "string") {
  442. return PasswordBasedCipher;
  443. } else {
  444. return SerializableCipher;
  445. }
  446. }
  447. return function(cipher) {
  448. return {
  449. encrypt: function(message, key, cfg) {
  450. return selectCipherStrategy(key).encrypt(cipher, message, key, cfg);
  451. },
  452. decrypt: function(ciphertext, key, cfg) {
  453. return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg);
  454. }
  455. };
  456. };
  457. }()
  458. });
  459. var StreamCipher = C_lib.StreamCipher = Cipher.extend({
  460. _doFinalize: function() {
  461. var finalProcessedBlocks = this._process(true);
  462. return finalProcessedBlocks;
  463. },
  464. blockSize: 1
  465. });
  466. var C_mode = C.mode = {};
  467. var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({
  468. /**
  469. * Creates this mode for encryption.
  470. *
  471. * @param {Cipher} cipher A block cipher instance.
  472. * @param {Array} iv The IV words.
  473. *
  474. * @static
  475. *
  476. * @example
  477. *
  478. * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
  479. */
  480. createEncryptor: function(cipher, iv) {
  481. return this.Encryptor.create(cipher, iv);
  482. },
  483. /**
  484. * Creates this mode for decryption.
  485. *
  486. * @param {Cipher} cipher A block cipher instance.
  487. * @param {Array} iv The IV words.
  488. *
  489. * @static
  490. *
  491. * @example
  492. *
  493. * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
  494. */
  495. createDecryptor: function(cipher, iv) {
  496. return this.Decryptor.create(cipher, iv);
  497. },
  498. /**
  499. * Initializes a newly created mode.
  500. *
  501. * @param {Cipher} cipher A block cipher instance.
  502. * @param {Array} iv The IV words.
  503. *
  504. * @example
  505. *
  506. * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
  507. */
  508. init: function(cipher, iv) {
  509. this._cipher = cipher;
  510. this._iv = iv;
  511. }
  512. });
  513. var CBC = C_mode.CBC = function() {
  514. var CBC2 = BlockCipherMode.extend();
  515. CBC2.Encryptor = CBC2.extend({
  516. /**
  517. * Processes the data block at offset.
  518. *
  519. * @param {Array} words The data words to operate on.
  520. * @param {number} offset The offset where the block starts.
  521. *
  522. * @example
  523. *
  524. * mode.processBlock(data.words, offset);
  525. */
  526. processBlock: function(words, offset) {
  527. var cipher = this._cipher;
  528. var blockSize = cipher.blockSize;
  529. xorBlock.call(this, words, offset, blockSize);
  530. cipher.encryptBlock(words, offset);
  531. this._prevBlock = words.slice(offset, offset + blockSize);
  532. }
  533. });
  534. CBC2.Decryptor = CBC2.extend({
  535. /**
  536. * Processes the data block at offset.
  537. *
  538. * @param {Array} words The data words to operate on.
  539. * @param {number} offset The offset where the block starts.
  540. *
  541. * @example
  542. *
  543. * mode.processBlock(data.words, offset);
  544. */
  545. processBlock: function(words, offset) {
  546. var cipher = this._cipher;
  547. var blockSize = cipher.blockSize;
  548. var thisBlock = words.slice(offset, offset + blockSize);
  549. cipher.decryptBlock(words, offset);
  550. xorBlock.call(this, words, offset, blockSize);
  551. this._prevBlock = thisBlock;
  552. }
  553. });
  554. function xorBlock(words, offset, blockSize) {
  555. var block;
  556. var iv = this._iv;
  557. if (iv) {
  558. block = iv;
  559. this._iv = undefined;
  560. } else {
  561. block = this._prevBlock;
  562. }
  563. for (var i = 0; i < blockSize; i++) {
  564. words[offset + i] ^= block[i];
  565. }
  566. }
  567. return CBC2;
  568. }();
  569. var C_pad = C.pad = {};
  570. var Pkcs7 = C_pad.Pkcs7 = {
  571. /**
  572. * Pads data using the algorithm defined in PKCS #5/7.
  573. *
  574. * @param {WordArray} data The data to pad.
  575. * @param {number} blockSize The multiple that the data should be padded to.
  576. *
  577. * @static
  578. *
  579. * @example
  580. *
  581. * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
  582. */
  583. pad: function(data, blockSize) {
  584. var blockSizeBytes = blockSize * 4;
  585. var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes;
  586. var paddingWord = nPaddingBytes << 24 | nPaddingBytes << 16 | nPaddingBytes << 8 | nPaddingBytes;
  587. var paddingWords = [];
  588. for (var i = 0; i < nPaddingBytes; i += 4) {
  589. paddingWords.push(paddingWord);
  590. }
  591. var padding = WordArray.create(paddingWords, nPaddingBytes);
  592. data.concat(padding);
  593. },
  594. /**
  595. * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
  596. *
  597. * @param {WordArray} data The data to unpad.
  598. *
  599. * @static
  600. *
  601. * @example
  602. *
  603. * CryptoJS.pad.Pkcs7.unpad(wordArray);
  604. */
  605. unpad: function(data) {
  606. var nPaddingBytes = data.words[data.sigBytes - 1 >>> 2] & 255;
  607. data.sigBytes -= nPaddingBytes;
  608. }
  609. };
  610. var BlockCipher = C_lib.BlockCipher = Cipher.extend({
  611. /**
  612. * Configuration options.
  613. *
  614. * @property {Mode} mode The block mode to use. Default: CBC
  615. * @property {Padding} padding The padding strategy to use. Default: Pkcs7
  616. */
  617. cfg: Cipher.cfg.extend({
  618. mode: CBC,
  619. padding: Pkcs7
  620. }),
  621. reset: function() {
  622. var modeCreator;
  623. Cipher.reset.call(this);
  624. var cfg = this.cfg;
  625. var iv = cfg.iv;
  626. var mode = cfg.mode;
  627. if (this._xformMode == this._ENC_XFORM_MODE) {
  628. modeCreator = mode.createEncryptor;
  629. } else {
  630. modeCreator = mode.createDecryptor;
  631. this._minBufferSize = 1;
  632. }
  633. if (this._mode && this._mode.__creator == modeCreator) {
  634. this._mode.init(this, iv && iv.words);
  635. } else {
  636. this._mode = modeCreator.call(mode, this, iv && iv.words);
  637. this._mode.__creator = modeCreator;
  638. }
  639. },
  640. _doProcessBlock: function(words, offset) {
  641. this._mode.processBlock(words, offset);
  642. },
  643. _doFinalize: function() {
  644. var finalProcessedBlocks;
  645. var padding = this.cfg.padding;
  646. if (this._xformMode == this._ENC_XFORM_MODE) {
  647. padding.pad(this._data, this.blockSize);
  648. finalProcessedBlocks = this._process(true);
  649. } else {
  650. finalProcessedBlocks = this._process(true);
  651. padding.unpad(finalProcessedBlocks);
  652. }
  653. return finalProcessedBlocks;
  654. },
  655. blockSize: 128 / 32
  656. });
  657. var CipherParams = C_lib.CipherParams = Base.extend({
  658. /**
  659. * Initializes a newly created cipher params object.
  660. *
  661. * @param {Object} cipherParams An object with any of the possible cipher parameters.
  662. *
  663. * @example
  664. *
  665. * var cipherParams = CryptoJS.lib.CipherParams.create({
  666. * ciphertext: ciphertextWordArray,
  667. * key: keyWordArray,
  668. * iv: ivWordArray,
  669. * salt: saltWordArray,
  670. * algorithm: CryptoJS.algo.AES,
  671. * mode: CryptoJS.mode.CBC,
  672. * padding: CryptoJS.pad.PKCS7,
  673. * blockSize: 4,
  674. * formatter: CryptoJS.format.OpenSSL
  675. * });
  676. */
  677. init: function(cipherParams) {
  678. this.mixIn(cipherParams);
  679. },
  680. /**
  681. * Converts this cipher params object to a string.
  682. *
  683. * @param {Format} formatter (Optional) The formatting strategy to use.
  684. *
  685. * @return {string} The stringified cipher params.
  686. *
  687. * @throws Error If neither the formatter nor the default formatter is set.
  688. *
  689. * @example
  690. *
  691. * var string = cipherParams + '';
  692. * var string = cipherParams.toString();
  693. * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
  694. */
  695. toString: function(formatter) {
  696. return (formatter || this.formatter).stringify(this);
  697. }
  698. });
  699. var C_format = C.format = {};
  700. var OpenSSLFormatter = C_format.OpenSSL = {
  701. /**
  702. * Converts a cipher params object to an OpenSSL-compatible string.
  703. *
  704. * @param {CipherParams} cipherParams The cipher params object.
  705. *
  706. * @return {string} The OpenSSL-compatible string.
  707. *
  708. * @static
  709. *
  710. * @example
  711. *
  712. * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
  713. */
  714. stringify: function(cipherParams) {
  715. var wordArray;
  716. var ciphertext = cipherParams.ciphertext;
  717. var salt = cipherParams.salt;
  718. if (salt) {
  719. wordArray = WordArray.create([1398893684, 1701076831]).concat(salt).concat(ciphertext);
  720. } else {
  721. wordArray = ciphertext;
  722. }
  723. return wordArray.toString(Base64);
  724. },
  725. /**
  726. * Converts an OpenSSL-compatible string to a cipher params object.
  727. *
  728. * @param {string} openSSLStr The OpenSSL-compatible string.
  729. *
  730. * @return {CipherParams} The cipher params object.
  731. *
  732. * @static
  733. *
  734. * @example
  735. *
  736. * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
  737. */
  738. parse: function(openSSLStr) {
  739. var salt;
  740. var ciphertext = Base64.parse(openSSLStr);
  741. var ciphertextWords = ciphertext.words;
  742. if (ciphertextWords[0] == 1398893684 && ciphertextWords[1] == 1701076831) {
  743. salt = WordArray.create(ciphertextWords.slice(2, 4));
  744. ciphertextWords.splice(0, 4);
  745. ciphertext.sigBytes -= 16;
  746. }
  747. return CipherParams.create({ ciphertext, salt });
  748. }
  749. };
  750. var SerializableCipher = C_lib.SerializableCipher = Base.extend({
  751. /**
  752. * Configuration options.
  753. *
  754. * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
  755. */
  756. cfg: Base.extend({
  757. format: OpenSSLFormatter
  758. }),
  759. /**
  760. * Encrypts a message.
  761. *
  762. * @param {Cipher} cipher The cipher algorithm to use.
  763. * @param {WordArray|string} message The message to encrypt.
  764. * @param {WordArray} key The key.
  765. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  766. *
  767. * @return {CipherParams} A cipher params object.
  768. *
  769. * @static
  770. *
  771. * @example
  772. *
  773. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
  774. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
  775. * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  776. */
  777. encrypt: function(cipher, message, key, cfg) {
  778. cfg = this.cfg.extend(cfg);
  779. var encryptor = cipher.createEncryptor(key, cfg);
  780. var ciphertext = encryptor.finalize(message);
  781. var cipherCfg = encryptor.cfg;
  782. return CipherParams.create({
  783. ciphertext,
  784. key,
  785. iv: cipherCfg.iv,
  786. algorithm: cipher,
  787. mode: cipherCfg.mode,
  788. padding: cipherCfg.padding,
  789. blockSize: cipher.blockSize,
  790. formatter: cfg.format
  791. });
  792. },
  793. /**
  794. * Decrypts serialized ciphertext.
  795. *
  796. * @param {Cipher} cipher The cipher algorithm to use.
  797. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  798. * @param {WordArray} key The key.
  799. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  800. *
  801. * @return {WordArray} The plaintext.
  802. *
  803. * @static
  804. *
  805. * @example
  806. *
  807. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  808. * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
  809. */
  810. decrypt: function(cipher, ciphertext, key, cfg) {
  811. cfg = this.cfg.extend(cfg);
  812. ciphertext = this._parse(ciphertext, cfg.format);
  813. var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext);
  814. return plaintext;
  815. },
  816. /**
  817. * Converts serialized ciphertext to CipherParams,
  818. * else assumed CipherParams already and returns ciphertext unchanged.
  819. *
  820. * @param {CipherParams|string} ciphertext The ciphertext.
  821. * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
  822. *
  823. * @return {CipherParams} The unserialized ciphertext.
  824. *
  825. * @static
  826. *
  827. * @example
  828. *
  829. * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
  830. */
  831. _parse: function(ciphertext, format) {
  832. if (typeof ciphertext == "string") {
  833. return format.parse(ciphertext, this);
  834. } else {
  835. return ciphertext;
  836. }
  837. }
  838. });
  839. var C_kdf = C.kdf = {};
  840. var OpenSSLKdf = C_kdf.OpenSSL = {
  841. /**
  842. * Derives a key and IV from a password.
  843. *
  844. * @param {string} password The password to derive from.
  845. * @param {number} keySize The size in words of the key to generate.
  846. * @param {number} ivSize The size in words of the IV to generate.
  847. * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
  848. *
  849. * @return {CipherParams} A cipher params object with the key, IV, and salt.
  850. *
  851. * @static
  852. *
  853. * @example
  854. *
  855. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
  856. * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
  857. */
  858. execute: function(password, keySize, ivSize, salt) {
  859. if (!salt) {
  860. salt = WordArray.random(64 / 8);
  861. }
  862. var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
  863. var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
  864. key.sigBytes = keySize * 4;
  865. return CipherParams.create({ key, iv, salt });
  866. }
  867. };
  868. var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({
  869. /**
  870. * Configuration options.
  871. *
  872. * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
  873. */
  874. cfg: SerializableCipher.cfg.extend({
  875. kdf: OpenSSLKdf
  876. }),
  877. /**
  878. * Encrypts a message using a password.
  879. *
  880. * @param {Cipher} cipher The cipher algorithm to use.
  881. * @param {WordArray|string} message The message to encrypt.
  882. * @param {string} password The password.
  883. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  884. *
  885. * @return {CipherParams} A cipher params object.
  886. *
  887. * @static
  888. *
  889. * @example
  890. *
  891. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
  892. * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
  893. */
  894. encrypt: function(cipher, message, password, cfg) {
  895. cfg = this.cfg.extend(cfg);
  896. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize);
  897. cfg.iv = derivedParams.iv;
  898. var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg);
  899. ciphertext.mixIn(derivedParams);
  900. return ciphertext;
  901. },
  902. /**
  903. * Decrypts serialized ciphertext using a password.
  904. *
  905. * @param {Cipher} cipher The cipher algorithm to use.
  906. * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
  907. * @param {string} password The password.
  908. * @param {Object} cfg (Optional) The configuration options to use for this operation.
  909. *
  910. * @return {WordArray} The plaintext.
  911. *
  912. * @static
  913. *
  914. * @example
  915. *
  916. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
  917. * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
  918. */
  919. decrypt: function(cipher, ciphertext, password, cfg) {
  920. cfg = this.cfg.extend(cfg);
  921. ciphertext = this._parse(ciphertext, cfg.format);
  922. var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt);
  923. cfg.iv = derivedParams.iv;
  924. var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg);
  925. return plaintext;
  926. }
  927. });
  928. }();
  929. });
  930. }
  931. });
  932. export {
  933. require_evpkdf,
  934. require_cipher_core
  935. };
  936. //# sourceMappingURL=chunk-MIVSMGMR.js.map