1import "../../../../../_virtual/_commonjsHelpers.js"; 2import { __module as cipherCore$1 } from "../../../../../_virtual/cipher-core.js"; 3import { __require as requireCore } from "./core.js"; 4import { __require as requireEvpkdf } from "./evpkdf.js"; 5var cipherCore = cipherCore$1.exports; 6var hasRequiredCipherCore; 7function requireCipherCore() { 8 if (hasRequiredCipherCore) return cipherCore$1.exports; 9 hasRequiredCipherCore = 1; 10 (function(module, exports$1) { 11 ; 12 (function(root, factory, undef) { 13 if (true) { 14 module.exports = exports$1 = factory(requireCore(), requireEvpkdf()); 15 } else if (false) { 16 (void 0)(["./core", "./evpkdf"], factory); 17 } else { 18 factory(root.CryptoJS); 19 } 20 })(cipherCore, function(CryptoJS) { 21 CryptoJS.lib.Cipher || (function(undefined$1) { 22 var C = CryptoJS; 23 var C_lib = C.lib; 24 var Base = C_lib.Base; 25 var WordArray = C_lib.WordArray; 26 var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm; 27 var C_enc = C.enc; 28 var Utf8 = C_enc.Utf8; 29 var Base64 = C_enc.Base64; 30 var C_algo = C.algo; 31 var EvpKDF = C_algo.EvpKDF; 32 var Cipher = C_lib.Cipher = BufferedBlockAlgorithm.extend({ 33 /** 34 * Configuration options. 35 * 36 * @property {WordArray} iv The IV to use for this operation. 37 */ 38 cfg: Base.extend(), 39 /** 40 * Creates this cipher in encryption mode. 41 * 42 * @param {WordArray} key The key. 43 * @param {Object} cfg (Optional) The configuration options to use for this operation. 44 * 45 * @return {Cipher} A cipher instance. 46 * 47 * @static 48 * 49 * @example 50 * 51 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray }); 52 */ 53 createEncryptor: function(key, cfg) { 54 return this.create(this._ENC_XFORM_MODE, key, cfg); 55 }, 56 /** 57 * Creates this cipher in decryption mode. 58 * 59 * @param {WordArray} key The key. 60 * @param {Object} cfg (Optional) The configuration options to use for this operation. 61 * 62 * @return {Cipher} A cipher instance. 63 * 64 * @static 65 * 66 * @example 67 * 68 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray }); 69 */ 70 createDecryptor: function(key, cfg) { 71 return this.create(this._DEC_XFORM_MODE, key, cfg); 72 }, 73 /** 74 * Initializes a newly created cipher. 75 * 76 * @param {number} xformMode Either the encryption or decryption transormation mode constant. 77 * @param {WordArray} key The key. 78 * @param {Object} cfg (Optional) The configuration options to use for this operation. 79 * 80 * @example 81 * 82 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray }); 83 */ 84 init: function(xformMode, key, cfg) { 85 this.cfg = this.cfg.extend(cfg); 86 this._xformMode = xformMode; 87 this._key = key; 88 this.reset(); 89 }, 90 /** 91 * Resets this cipher to its initial state. 92 * 93 * @example 94 * 95 * cipher.reset(); 96 */ 97 reset: function() { 98 BufferedBlockAlgorithm.reset.call(this); 99 this._doReset(); 100 }, 101 /** 102 * Adds data to be encrypted or decrypted. 103 * 104 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt. 105 * 106 * @return {WordArray} The data after processing. 107 * 108 * @example 109 * 110 * var encrypted = cipher.process('data'); 111 * var encrypted = cipher.process(wordArray); 112 */ 113 process: function(dataUpdate) { 114 this._append(dataUpdate); 115 return this._process(); 116 }, 117 /** 118 * Finalizes the encryption or decryption process. 119 * Note that the finalize operation is effectively a destructive, read-once operation. 120 * 121 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt. 122 * 123 * @return {WordArray} The data after final processing. 124 * 125 * @example 126 * 127 * var encrypted = cipher.finalize(); 128 * var encrypted = cipher.finalize('data'); 129 * var encrypted = cipher.finalize(wordArray); 130 */ 131 finalize: function(dataUpdate) { 132 if (dataUpdate) { 133 this._append(dataUpdate); 134 } 135 var finalProcessedData = this._doFinalize(); 136 return finalProcessedData; 137 }, 138 keySize: 128 / 32, 139 ivSize: 128 / 32, 140 _ENC_XFORM_MODE: 1, 141 _DEC_XFORM_MODE: 2, 142 /** 143 * Creates shortcut functions to a cipher's object interface. 144 * 145 * @param {Cipher} cipher The cipher to create a helper for. 146 * 147 * @return {Object} An object with encrypt and decrypt shortcut functions. 148 * 149 * @static 150 * 151 * @example 152 * 153 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES); 154 */ 155 _createHelper: /* @__PURE__ */ (function() { 156 function selectCipherStrategy(key) { 157 if (typeof key == "string") { 158 return PasswordBasedCipher; 159 } else { 160 return SerializableCipher; 161 } 162 } 163 return function(cipher) { 164 return { 165 encrypt: function(message, key, cfg) {
vendor: 4,122 bytes, lines 166-284
166 return selectCipherStrategy(key).encrypt(cipher, message, key, cfg); 167 }, 168 decrypt: function(ciphertext, key, cfg) { 169 return selectCipherStrategy(key).decrypt(cipher, ciphertext, key, cfg); 170 } 171 }; 172 }; 173 })() 174 }); 175 var StreamCipher = C_lib.StreamCipher = Cipher.extend({ 176 _doFinalize: function() { 177 var finalProcessedBlocks = this._process(true); 178 return finalProcessedBlocks; 179 }, 180 blockSize: 1 181 }); 182 var C_mode = C.mode = {}; 183 var BlockCipherMode = C_lib.BlockCipherMode = Base.extend({ 184 /** 185 * Creates this mode for encryption. 186 * 187 * @param {Cipher} cipher A block cipher instance. 188 * @param {Array} iv The IV words. 189 * 190 * @static 191 * 192 * @example 193 * 194 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words); 195 */ 196 createEncryptor: function(cipher, iv) { 197 return this.Encryptor.create(cipher, iv); 198 }, 199 /** 200 * Creates this mode for decryption. 201 * 202 * @param {Cipher} cipher A block cipher instance. 203 * @param {Array} iv The IV words. 204 * 205 * @static 206 * 207 * @example 208 * 209 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words); 210 */ 211 createDecryptor: function(cipher, iv) { 212 return this.Decryptor.create(cipher, iv); 213 }, 214 /** 215 * Initializes a newly created mode. 216 * 217 * @param {Cipher} cipher A block cipher instance. 218 * @param {Array} iv The IV words. 219 * 220 * @example 221 * 222 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words); 223 */ 224 init: function(cipher, iv) { 225 this._cipher = cipher; 226 this._iv = iv; 227 } 228 }); 229 var CBC = C_mode.CBC = (function() { 230 var CBC2 = BlockCipherMode.extend(); 231 CBC2.Encryptor = CBC2.extend({ 232 /** 233 * Processes the data block at offset. 234 * 235 * @param {Array} words The data words to operate on. 236 * @param {number} offset The offset where the block starts. 237 * 238 * @example 239 * 240 * mode.processBlock(data.words, offset); 241 */ 242 processBlock: function(words, offset) { 243 var cipher = this._cipher; 244 var blockSize = cipher.blockSize; 245 xorBlock.call(this, words, offset, blockSize); 246 cipher.encryptBlock(words, offset); 247 this._prevBlock = words.slice(offset, offset + blockSize); 248 } 249 }); 250 CBC2.Decryptor = CBC2.extend({ 251 /** 252 * Processes the data block at offset. 253 * 254 * @param {Array} words The data words to operate on. 255 * @param {number} offset The offset where the block starts. 256 * 257 * @example 258 * 259 * mode.processBlock(data.words, offset); 260 */ 261 processBlock: function(words, offset) { 262 var cipher = this._cipher; 263 var blockSize = cipher.blockSize; 264 var thisBlock = words.slice(offset, offset + blockSize); 265 cipher.decryptBlock(words, offset); 266 xorBlock.call(this, words, offset, blockSize); 267 this._prevBlock = thisBlock; 268 } 269 }); 270 function xorBlock(words, offset, blockSize) { 271 var block; 272 var iv = this._iv; 273 if (iv) { 274 block = iv; 275 this._iv = undefined$1; 276 } else { 277 block = this._prevBlock; 278 } 279 for (var i = 0; i < blockSize; i++) { 280 words[offset + i] ^= block[i]; 281 } 282 } 283 return CBC2; 284 })
vendor: 6,736 bytes, lines 284-463
284(); 285 var C_pad = C.pad = {}; 286 var Pkcs7 = C_pad.Pkcs7 = { 287 /** 288 * Pads data using the algorithm defined in PKCS #5/7. 289 * 290 * @param {WordArray} data The data to pad. 291 * @param {number} blockSize The multiple that the data should be padded to. 292 * 293 * @static 294 * 295 * @example 296 * 297 * CryptoJS.pad.Pkcs7.pad(wordArray, 4); 298 */ 299 pad: function(data, blockSize) { 300 var blockSizeBytes = blockSize * 4; 301 var nPaddingBytes = blockSizeBytes - data.sigBytes % blockSizeBytes; 302 var paddingWord = nPaddingBytes << 24 | nPaddingBytes << 16 | nPaddingBytes << 8 | nPaddingBytes; 303 var paddingWords = []; 304 for (var i = 0; i < nPaddingBytes; i += 4) { 305 paddingWords.push(paddingWord); 306 } 307 var padding = WordArray.create(paddingWords, nPaddingBytes); 308 data.concat(padding); 309 }, 310 /** 311 * Unpads data that had been padded using the algorithm defined in PKCS #5/7. 312 * 313 * @param {WordArray} data The data to unpad. 314 * 315 * @static 316 * 317 * @example 318 * 319 * CryptoJS.pad.Pkcs7.unpad(wordArray); 320 */ 321 unpad: function(data) { 322 var nPaddingBytes = data.words[data.sigBytes - 1 >>> 2] & 255; 323 data.sigBytes -= nPaddingBytes; 324 } 325 }; 326 var BlockCipher = C_lib.BlockCipher = Cipher.extend({ 327 /** 328 * Configuration options. 329 * 330 * @property {Mode} mode The block mode to use. Default: CBC 331 * @property {Padding} padding The padding strategy to use. Default: Pkcs7 332 */ 333 cfg: Cipher.cfg.extend({ 334 mode: CBC, 335 padding: Pkcs7 336 }), 337 reset: function() { 338 var modeCreator; 339 Cipher.reset.call(this); 340 var cfg = this.cfg; 341 var iv = cfg.iv; 342 var mode = cfg.mode; 343 if (this._xformMode == this._ENC_XFORM_MODE) { 344 modeCreator = mode.createEncryptor; 345 } else { 346 modeCreator = mode.createDecryptor; 347 this._minBufferSize = 1; 348 } 349 if (this._mode && this._mode.__creator == modeCreator) { 350 this._mode.init(this, iv && iv.words); 351 } else { 352 this._mode = modeCreator.call(mode, this, iv && iv.words); 353 this._mode.__creator = modeCreator; 354 } 355 }, 356 _doProcessBlock: function(words, offset) { 357 this._mode.processBlock(words, offset); 358 }, 359 _doFinalize: function() { 360 var finalProcessedBlocks; 361 var padding = this.cfg.padding; 362 if (this._xformMode == this._ENC_XFORM_MODE) { 363 padding.pad(this._data, this.blockSize); 364 finalProcessedBlocks = this._process(true); 365 } else { 366 finalProcessedBlocks = this._process(true); 367 padding.unpad(finalProcessedBlocks); 368 } 369 return finalProcessedBlocks; 370 }, 371 blockSize: 128 / 32 372 }); 373 var CipherParams = C_lib.CipherParams = Base.extend({ 374 /** 375 * Initializes a newly created cipher params object. 376 * 377 * @param {Object} cipherParams An object with any of the possible cipher parameters. 378 * 379 * @example 380 * 381 * var cipherParams = CryptoJS.lib.CipherParams.create({ 382 * ciphertext: ciphertextWordArray, 383 * key: keyWordArray, 384 * iv: ivWordArray, 385 * salt: saltWordArray, 386 * algorithm: CryptoJS.algo.AES, 387 * mode: CryptoJS.mode.CBC, 388 * padding: CryptoJS.pad.PKCS7, 389 * blockSize: 4, 390 * formatter: CryptoJS.format.OpenSSL 391 * }); 392 */ 393 init: function(cipherParams) { 394 this.mixIn(cipherParams); 395 }, 396 /** 397 * Converts this cipher params object to a string. 398 * 399 * @param {Format} formatter (Optional) The formatting strategy to use. 400 * 401 * @return {string} The stringified cipher params. 402 * 403 * @throws Error If neither the formatter nor the default formatter is set. 404 * 405 * @example 406 * 407 * var string = cipherParams + ''; 408 * var string = cipherParams.toString(); 409 * var string = cipherParams.toString(CryptoJS.format.OpenSSL); 410 */ 411 toString: function(formatter) { 412 return (formatter || this.formatter).stringify(this); 413 } 414 }); 415 var C_format = C.format = {}; 416 var OpenSSLFormatter = C_format.OpenSSL = { 417 /** 418 * Converts a cipher params object to an OpenSSL-compatible string. 419 * 420 * @param {CipherParams} cipherParams The cipher params object. 421 * 422 * @return {string} The OpenSSL-compatible string. 423 * 424 * @static 425 * 426 * @example 427 * 428 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams); 429 */ 430 stringify: function(cipherParams) { 431 var wordArray; 432 var ciphertext = cipherParams.ciphertext; 433 var salt = cipherParams.salt; 434 if (salt) { 435 wordArray = WordArray.create([1398893684, 1701076831]).concat(salt).concat(ciphertext); 436 } else { 437 wordArray = ciphertext; 438 } 439 return wordArray.toString(Base64); 440 }, 441 /** 442 * Converts an OpenSSL-compatible string to a cipher params object. 443 * 444 * @param {string} openSSLStr The OpenSSL-compatible string. 445 * 446 * @return {CipherParams} The cipher params object. 447 * 448 * @static 449 * 450 * @example 451 * 452 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString); 453 */ 454 parse: function(openSSLStr) { 455 var salt; 456 var ciphertext = Base64.parse(openSSLStr); 457 var ciphertextWords = ciphertext.words; 458 if (ciphertextWords[0] == 1398893684 && ciphertextWords[1] == 1701076831) { 459 salt = WordArray.create(ciphertextWords.slice(2, 4)); 460 ciphertextWords.splice(0, 4); 461 ciphertext.sigBytes -= 16; 462 } 463 return CipherParams.create({
463 ciphertext, salt }); 464 } 465 }; 466 var SerializableCipher = C_lib.SerializableCipher = Base.extend({ 467 /** 468 * Configuration options. 469 * 470 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL 471 */ 472 cfg: Base.extend({
vendor: 8,218 bytes, lines 473-655
473 format: OpenSSLFormatter 474 }), 475 /** 476 * Encrypts a message. 477 * 478 * @param {Cipher} cipher The cipher algorithm to use. 479 * @param {WordArray|string} message The message to encrypt. 480 * @param {WordArray} key The key. 481 * @param {Object} cfg (Optional) The configuration options to use for this operation. 482 * 483 * @return {CipherParams} A cipher params object. 484 * 485 * @static 486 * 487 * @example 488 * 489 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key); 490 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv }); 491 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 492 */ 493 encrypt: function(cipher, message, key, cfg) { 494 cfg = this.cfg.extend(cfg); 495 var encryptor = cipher.createEncryptor(key, cfg); 496 var ciphertext = encryptor.finalize(message); 497 var cipherCfg = encryptor.cfg; 498 return CipherParams.create({ 499 ciphertext, 500 key, 501 iv: cipherCfg.iv, 502 algorithm: cipher, 503 mode: cipherCfg.mode, 504 padding: cipherCfg.padding, 505 blockSize: cipher.blockSize, 506 formatter: cfg.format 507 }); 508 }, 509 /** 510 * Decrypts serialized ciphertext. 511 * 512 * @param {Cipher} cipher The cipher algorithm to use. 513 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 514 * @param {WordArray} key The key. 515 * @param {Object} cfg (Optional) The configuration options to use for this operation. 516 * 517 * @return {WordArray} The plaintext. 518 * 519 * @static 520 * 521 * @example 522 * 523 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 524 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL }); 525 */ 526 decrypt: function(cipher, ciphertext, key, cfg) { 527 cfg = this.cfg.extend(cfg); 528 ciphertext = this._parse(ciphertext, cfg.format); 529 var plaintext = cipher.createDecryptor(key, cfg).finalize(ciphertext.ciphertext); 530 return plaintext; 531 }, 532 /** 533 * Converts serialized ciphertext to CipherParams, 534 * else assumed CipherParams already and returns ciphertext unchanged. 535 * 536 * @param {CipherParams|string} ciphertext The ciphertext. 537 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext. 538 * 539 * @return {CipherParams} The unserialized ciphertext. 540 * 541 * @static 542 * 543 * @example 544 * 545 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format); 546 */ 547 _parse: function(ciphertext, format) { 548 if (typeof ciphertext == "string") { 549 return format.parse(ciphertext, this); 550 } else { 551 return ciphertext; 552 } 553 } 554 }); 555 var C_kdf = C.kdf = {}; 556 var OpenSSLKdf = C_kdf.OpenSSL = { 557 /** 558 * Derives a key and IV from a password. 559 * 560 * @param {string} password The password to derive from. 561 * @param {number} keySize The size in words of the key to generate. 562 * @param {number} ivSize The size in words of the IV to generate. 563 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly. 564 * 565 * @return {CipherParams} A cipher params object with the key, IV, and salt. 566 * 567 * @static 568 * 569 * @example 570 * 571 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32); 572 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt'); 573 */ 574 execute: function(password, keySize, ivSize, salt, hasher) { 575 if (!salt) { 576 salt = WordArray.random(64 / 8); 577 } 578 if (!hasher) { 579 var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt); 580 } else { 581 var key = EvpKDF.create({ keySize: keySize + ivSize, hasher }).compute(password, salt); 582 } 583 var iv = WordArray.create(key.words.slice(keySize), ivSize * 4); 584 key.sigBytes = keySize * 4; 585 return CipherParams.create({ key, iv, salt }); 586 } 587 }; 588 var PasswordBasedCipher = C_lib.PasswordBasedCipher = SerializableCipher.extend({ 589 /** 590 * Configuration options. 591 * 592 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL 593 */ 594 cfg: SerializableCipher.cfg.extend({ 595 kdf: OpenSSLKdf 596 }), 597 /** 598 * Encrypts a message using a password. 599 * 600 * @param {Cipher} cipher The cipher algorithm to use. 601 * @param {WordArray|string} message The message to encrypt. 602 * @param {string} password The password. 603 * @param {Object} cfg (Optional) The configuration options to use for this operation. 604 * 605 * @return {CipherParams} A cipher params object. 606 * 607 * @static 608 * 609 * @example 610 * 611 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password'); 612 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL }); 613 */ 614 encrypt: function(cipher, message, password, cfg) { 615 cfg = this.cfg.extend(cfg); 616 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, cfg.salt, cfg.hasher); 617 cfg.iv = derivedParams.iv; 618 var ciphertext = SerializableCipher.encrypt.call(this, cipher, message, derivedParams.key, cfg); 619 ciphertext.mixIn(derivedParams); 620 return ciphertext; 621 }, 622 /** 623 * Decrypts serialized ciphertext using a password. 624 * 625 * @param {Cipher} cipher The cipher algorithm to use. 626 * @param {CipherParams|string} ciphertext The ciphertext to decrypt. 627 * @param {string} password The password. 628 * @param {Object} cfg (Optional) The configuration options to use for this operation. 629 * 630 * @return {WordArray} The plaintext. 631 * 632 * @static 633 * 634 * @example 635 * 636 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL }); 637 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL }); 638 */ 639 decrypt: function(cipher, ciphertext, password, cfg) { 640 cfg = this.cfg.extend(cfg); 641 ciphertext = this._parse(ciphertext, cfg.format); 642 var derivedParams = cfg.kdf.execute(password, cipher.keySize, cipher.ivSize, ciphertext.salt, cfg.hasher); 643 cfg.iv = derivedParams.iv; 644 var plaintext = SerializableCipher.decrypt.call(this, cipher, ciphertext, derivedParams.key, cfg); 645 return plaintext; 646 } 647 }); 648 })(); 649 }); 650 })(cipherCore$1, cipherCore$1.exports); 651 return cipherCore$1.exports; 652} 653export { 654 requireCipherCore as __require 655};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.