UNPKG

54.3 kBTypeScriptView Raw
1export = CryptoJS;
2
3type WordArray = CryptoJS.lib.WordArray;
4type CipherParams = CryptoJS.lib.CipherParams;
5type X64Word = CryptoJS.x64.Word;
6
7/**
8 * Encoding strategy.
9 */
10interface Encoder {
11 /**
12 * Converts a word array to a hex string.
13 *
14 * @param wordArray The word array.
15 *
16 * @return The hex string.
17 *
18 * @example
19 *
20 * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
21 */
22 stringify(wordArray: WordArray): string;
23 /**
24 * Converts a hex string to a word array.
25 *
26 * @param hexStr The hex string.
27 *
28 * @return The word array.
29 *
30 * @example
31 *
32 * var wordArray = CryptoJS.enc.Hex.parse(hexString);
33 */
34 parse(str: string): WordArray;
35}
36
37/**
38 * Abstract buffered block algorithm template.
39 *
40 * The property blockSize must be implemented in a concrete subtype.
41 */
42interface BufferedBlockAlgorithm {
43 /**
44 * The number of blocks that should be kept unprocessed in the buffer. Default: 0
45 */
46 _minBufferSize: number;
47 /**
48 * Resets this block algorithm's data buffer to its initial state.
49 *
50 * @example
51 *
52 * bufferedBlockAlgorithm.reset();
53 */
54 reset(): void;
55 /**
56 * Adds new data to this block algorithm's buffer.
57 *
58 * @param data The data to append. Strings are converted to a WordArray using UTF-8.
59 *
60 * @example
61 *
62 * bufferedBlockAlgorithm._append('data');
63 * bufferedBlockAlgorithm._append(wordArray);
64 */
65 _append(data: WordArray | string): void;
66 /**
67 * Processes available data blocks.
68 *
69 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
70 *
71 * @param doFlush Whether all blocks and partial blocks should be processed.
72 *
73 * @return The processed data.
74 *
75 * @example
76 *
77 * var processedData = bufferedBlockAlgorithm._process();
78 * var processedData = bufferedBlockAlgorithm._process(!!'flush');
79 */
80 _process(doFlush?: boolean): WordArray;
81 /**
82 * Creates a copy of this object.
83 *
84 * @return The clone.
85 *
86 * @example
87 *
88 * var clone = bufferedBlockAlgorithm.clone();
89 */
90 clone(): BufferedBlockAlgorithm;
91}
92
93/**
94 * Abstract hasher template.
95 */
96interface Hasher {
97 /**
98 * The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
99 */
100 blockSize: number;
101 /**
102 * Resets this hasher to its initial state.
103 *
104 * @example
105 *
106 * hasher.reset();
107 */
108 reset(): void;
109 /**
110 * Updates this hasher with a message.
111 *
112 * @param messageUpdate The message to append.
113 *
114 * @return This hasher.
115 *
116 * @example
117 *
118 * hasher.update('message');
119 * hasher.update(wordArray);
120 */
121 update(messageUpdate: WordArray | string): this;
122 /**
123 * Finalizes the hash computation.
124 * Note that the finalize operation is effectively a destructive, read-once operation.
125 *
126 * @param messageUpdate (Optional) A final message update.
127 *
128 * @return The hash.
129 *
130 * @example
131 *
132 * var hash = hasher.finalize();
133 * var hash = hasher.finalize('message');
134 * var hash = hasher.finalize(wordArray);
135 */
136 finalize(messageUpdate?: WordArray | string): WordArray;
137}
138
139interface HasherStatic {
140 /**
141 * Initializes a newly created hasher.
142 *
143 * @param cfg (Optional) The configuration options to use for this hash computation.
144 *
145 * @example
146 *
147 * var hasher = CryptoJS.algo.SHA256.create();
148 */
149 create(cfg?: object): Hasher;
150}
151
152interface HasherHelper {
153 (message: WordArray | string, cfg?: object): WordArray;
154}
155
156interface HmacHasherHelper {
157 (message: WordArray | string, key: WordArray | string): WordArray;
158}
159
160/**
161 * Abstract base cipher template.
162 */
163interface Cipher {
164 /**
165 * This cipher's key size. Default: 4 (128 bits)
166 */
167 keySize: number;
168 /**
169 * This cipher's IV size. Default: 4 (128 bits)
170 */
171 ivSize: number;
172 /**
173 * A constant representing encryption mode.
174 */
175 readonly _ENC_XFORM_MODE: number;
176 /**
177 * A constant representing decryption mode.
178 */
179 readonly _DEV_XFORM_MODE: number;
180
181 /**
182 * Resets this cipher to its initial state.
183 *
184 * @example
185 *
186 * cipher.reset();
187 */
188 reset(): void;
189
190 /**
191 * Adds data to be encrypted or decrypted.
192 *
193 * @param dataUpdate The data to encrypt or decrypt.
194 *
195 * @return The data after processing.
196 *
197 * @example
198 *
199 * var encrypted = cipher.process('data');
200 * var encrypted = cipher.process(wordArray);
201 */
202 process(dataUpdate: WordArray | string): WordArray;
203
204 /**
205 * Finalizes the encryption or decryption process.
206 * Note that the finalize operation is effectively a destructive, read-once operation.
207 *
208 * @param dataUpdate The final data to encrypt or decrypt.
209 *
210 * @return The data after final processing.
211 *
212 * @example
213 *
214 * var encrypted = cipher.finalize();
215 * var encrypted = cipher.finalize('data');
216 * var encrypted = cipher.finalize(wordArray);
217 */
218 finalize(dataUpdate?: WordArray | string): WordArray;
219}
220
221interface CipherStatic {
222 /**
223 * Creates this cipher in encryption mode.
224 *
225 * @param key The key.
226 * @param cfg (Optional) The configuration options to use for this operation.
227 *
228 * @return A cipher instance.
229 *
230 * @example
231 *
232 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
233 */
234 createEncryptor(key: WordArray, cfg?: CipherOption): Cipher;
235
236 /**
237 * Creates this cipher in decryption mode.
238 *
239 * @param key The key.
240 * @param cfg (Optional) The configuration options to use for this operation.
241 *
242 * @return A cipher instance.
243 *
244 * @example
245 *
246 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
247 */
248 createDecryptor(key: WordArray, cfg?: CipherOption): Cipher;
249
250 /**
251 * Initializes a newly created cipher.
252 *
253 * @param xformMode Either the encryption or decryption transormation mode constant.
254 * @param key The key.
255 * @param cfg (Optional) The configuration options to use for this operation.
256 *
257 * @example
258 *
259 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
260 */
261 create(xformMode: number, key: WordArray, cfg?: CipherOption): Cipher;
262}
263
264interface CipherHelper {
265 encrypt(message: WordArray | string, key: WordArray | string, cfg?: CipherOption): CipherParams;
266 decrypt(ciphertext: CipherParams | string, key: WordArray | string, cfg?: CipherOption): WordArray;
267}
268
269/**
270 * Configuration options.
271 */
272interface CipherOption {
273 /**
274 * The IV to use for this operation.
275 */
276 iv?: WordArray | undefined;
277 format?: Format | undefined;
278 [key: string]: any;
279}
280
281interface Mode {
282 /**
283 * Processes the data block at offset.
284 *
285 * @param words The data words to operate on.
286 * @param offset The offset where the block starts.
287 *
288 * @example
289 *
290 * mode.processBlock(data.words, offset);
291 */
292 processBlock(words: number[], offset: number): void;
293}
294
295interface ModeStatic {
296 /**
297 * Initializes a newly created mode.
298 *
299 * @param cipher A block cipher instance.
300 * @param iv The IV words.
301 *
302 * @example
303 *
304 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
305 */
306 create(cipher: Cipher, iv: number[]): Mode;
307}
308
309/**
310 * Abstract base block cipher mode template.
311 */
312interface BlockCipherMode {
313 Encryptor: ModeStatic;
314 Decryptor: ModeStatic;
315 /**
316 * Creates this mode for encryption.
317 *
318 * @param cipher A block cipher instance.
319 * @param iv The IV words.
320 *
321 * @example
322 *
323 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
324 */
325 createEncryptor(cipher: Cipher, iv: number[]): Mode;
326
327 /**
328 * Creates this mode for decryption.
329 *
330 * @param cipher A block cipher instance.
331 * @param iv The IV words.
332 *
333 * @example
334 *
335 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
336 */
337 createDecryptor(cipher: Cipher, iv: number[]): Mode;
338}
339
340/**
341 * Abstract base block cipher mode template.
342 */
343interface BlockCipherMode {
344 /**
345 * Creates this mode for encryption.
346 *
347 * @param cipher A block cipher instance.
348 * @param iv The IV words.
349 *
350 * @example
351 *
352 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
353 */
354 createEncryptor(cipher: Cipher): Mode;
355}
356
357/**
358 * Padding strategy.
359 */
360interface Padding {
361 /**
362 * Pads data using the algorithm defined in PKCS #5/7.
363 *
364 * @param data The data to pad.
365 * @param blockSize The multiple that the data should be padded to.
366 *
367 * @example
368 *
369 * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
370 */
371 pad(data: WordArray, blockSize: number): void;
372
373 /**
374 * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
375 *
376 * @param data The data to unpad.
377 *
378 * @example
379 *
380 * CryptoJS.pad.Pkcs7.unpad(wordArray);
381 */
382 unpad(data: WordArray): void;
383}
384
385/**
386 * Abstract base block cipher template.
387 */
388interface BlockCipher {
389 /**
390 * The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
391 */
392 blockSize: number;
393}
394
395/**
396 * Configuration options.
397 */
398interface BlockCipherOption {
399 /**
400 * The block mode to use. Default: CBC
401 */
402 mode: Mode;
403 /**
404 * The padding strategy to use. Default: Pkcs7
405 */
406 padding: Padding;
407}
408/**
409 * Formatting strategy.
410 */
411interface Format {
412 /**
413 * Converts a cipher params object to an OpenSSL-compatible string.
414 *
415 * @param cipherParams The cipher params object.
416 *
417 * @return The OpenSSL-compatible string.
418 *
419 * @example
420 *
421 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
422 */
423 stringify(cipherParams: CipherParams): string;
424
425 /**
426 * Converts an OpenSSL-compatible string to a cipher params object.
427 *
428 * @param openSSLStr The OpenSSL-compatible string.
429 *
430 * @return The cipher params object.
431 *
432 * @example
433 *
434 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
435 */
436 parse(str: string): CipherParams;
437}
438
439/**
440 * An array of 64-bit words.
441 */
442interface X64WordArray {
443 /**
444 * The array of CryptoJS.x64.Word objects.
445 */
446 words: number[];
447 /**
448 * The number of significant bytes in this word array.
449 */
450 sigBytes: number;
451
452 /**
453 * Converts this 64-bit word array to a 32-bit word array.
454 *
455 * @return This word array's data as a 32-bit word array.
456 *
457 * @example
458 *
459 * var x32WordArray = x64WordArray.toX32();
460 */
461 toX32(): WordArray;
462
463 /**
464 * Creates a copy of this word array.
465 *
466 * @return The clone.
467 *
468 * @example
469 *
470 * var clone = x64WordArray.clone();
471 */
472 clone(): X64WordArray;
473}
474
475/**
476 * Base object for prototypal inheritance.
477 */
478interface Base {
479 /**
480 * Creates a copy of this object.
481 *
482 * @return The clone.
483 *
484 * @example
485 *
486 * var clone = instance.clone();
487 */
488 clone(): this;
489}
490
491/**
492 * Configuration options.
493 */
494interface KDFOption {
495 /**
496 * The key size in words to generate.
497 */
498 keySize?: number | undefined;
499 /**
500 * The hasher to use.
501 */
502 hasher?: HasherStatic | undefined;
503 /**
504 * The number of iterations to perform.
505 */
506 iterations?: number | undefined;
507}
508
509declare global {
510 namespace CryptoJS {
511 /**
512 * Library namespace.
513 */
514 export namespace lib {
515 /**
516 * Base object for prototypal inheritance.
517 */
518 const Base: {
519 /**
520 * Creates a new object that inherits from this object.
521 *
522 * @param overrides Properties to copy into the new object.
523 *
524 * @return The new object.
525 *
526 * @example
527 *
528 * var MyType = CryptoJS.lib.Base.extend({
529 * field: 'value',
530 *
531 * method: function () {
532 * }
533 * });
534 */
535 extend(overrides: object): any;
536
537 /**
538 * Extends this object and runs the init method.
539 * Arguments to create() will be passed to init().
540 *
541 * @return The new object.
542 *
543 * @example
544 *
545 * var instance = MyType.create();
546 */
547 create(...args: any[]): any;
548
549 /**
550 * Copies properties into this object.
551 *
552 * @param properties The properties to mix in.
553 *
554 * @example
555 *
556 * MyType.mixIn({
557 * field: 'value'
558 * });
559 */
560 mixIn(properties: object): any;
561 };
562
563 /**
564 * An array of 32-bit words.
565 */
566 interface WordArray {
567 /**
568 * The array of 32-bit words.
569 */
570 words: number[];
571 /**
572 * The number of significant bytes in this word array.
573 */
574 sigBytes: number;
575 /**
576 * Converts this word array to a string.
577 *
578 * @param encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
579 *
580 * @return The stringified word array.
581 *
582 * @example
583 *
584 * var string = wordArray + '';
585 * var string = wordArray.toString();
586 * var string = wordArray.toString(CryptoJS.enc.Utf8);
587 */
588 toString(encoder?: Encoder): string;
589
590 /**
591 * Concatenates a word array to this word array.
592 *
593 * @param wordArray The word array to append.
594 *
595 * @return This word array.
596 *
597 * @example
598 *
599 * wordArray1.concat(wordArray2);
600 */
601 concat(wordArray: WordArray): this;
602
603 /**
604 * Removes insignificant bits.
605 *
606 * @example
607 *
608 * wordArray.clamp();
609 */
610 clamp(): void;
611
612 /**
613 * Creates a copy of this word array.
614 *
615 * @return The clone.
616 *
617 * @example
618 *
619 * var clone = wordArray.clone();
620 */
621 clone(): WordArray;
622 }
623 const WordArray: {
624 /**
625 * Initializes a newly created word array.
626 *
627 * @param words (Optional) An array of 32-bit words.
628 * @param sigBytes (Optional) The number of significant bytes in the words.
629 *
630 * @example
631 *
632 * var wordArray = CryptoJS.lib.WordArray.create();
633 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
634 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
635 */
636 create(
637 words?:
638 | number[]
639 | ArrayBuffer
640 | Uint8Array
641 | Int8Array
642 | Uint8ClampedArray
643 | Int16Array
644 | Uint16Array
645 | Int32Array
646 | Uint32Array
647 | Float32Array
648 | Float64Array,
649 sigBytes?: number,
650 ): WordArray;
651 /**
652 * Creates a word array filled with random bytes.
653 *
654 * @param nBytes The number of random bytes to generate.
655 *
656 * @return The random word array.
657 *
658 * @example
659 *
660 * var wordArray = CryptoJS.lib.WordArray.random(16);
661 */
662 random(nBytes: number): WordArray;
663 };
664
665 const BufferedBlockAlgorithm: any;
666
667 const Hasher: {
668 /**
669 * Creates a shortcut function to a hasher's object interface.
670 *
671 * @param hasher The hasher to create a helper for.
672 *
673 * @return The shortcut function.
674 *
675 * @example
676 *
677 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
678 */
679 _createHelper(hasher: HasherStatic): HasherHelper;
680 /**
681 * Creates a shortcut function to the HMAC's object interface.
682 *
683 * @param hasher The hasher to use in this HMAC helper.
684 *
685 * @return The shortcut function.
686 *
687 * @example
688 *
689 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
690 */
691 _createHmacHelper(hasher: HasherStatic): HmacHasherHelper;
692 };
693
694 const Cipher: {
695 /**
696 * Creates shortcut functions to a cipher's object interface.
697 *
698 * @param cipher The cipher to create a helper for.
699 *
700 * @return An object with encrypt and decrypt shortcut functions.
701 *
702 * @example
703 *
704 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
705 */
706 _createHelper(cipher: Cipher): CipherHelper;
707 };
708
709 /**
710 * A collection of cipher parameters.
711 */
712 interface CipherParams {
713 /**
714 * The raw ciphertext.
715 */
716 ciphertext: WordArray;
717 /**
718 * The key to this ciphertext.
719 */
720 key: WordArray;
721 /**
722 * The IV used in the ciphering operation.
723 */
724 iv: WordArray;
725 /**
726 * The salt used with a key derivation function.
727 */
728 salt: WordArray;
729 /**
730 * The cipher algorithm.
731 */
732 algorithm: CipherStatic;
733 /**
734 * The block mode used in the ciphering operation.
735 */
736 mode: Mode;
737 /**
738 * The padding scheme used in the ciphering operation.
739 */
740 padding: Padding;
741 /**
742 * The block size of the cipher.
743 */
744 blockSize: number;
745 /**
746 * The default formatting strategy to convert this cipher params object to a string.
747 */
748 formatter: Format;
749 /**
750 * Converts this cipher params object to a string.
751 *
752 * @param formatter (Optional) The formatting strategy to use.
753 *
754 * @return The stringified cipher params.
755 *
756 * @throws Error If neither the formatter nor the default formatter is set.
757 *
758 * @example
759 *
760 * var string = cipherParams + '';
761 * var string = cipherParams.toString();
762 * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
763 */
764 toString(formatter?: Format): string;
765 }
766 const CipherParams: {
767 /**
768 * Initializes a newly created cipher params object.
769 *
770 * @param cipherParams An object with any of the possible cipher parameters.
771 *
772 * @example
773 *
774 * var cipherParams = CryptoJS.lib.CipherParams.create({
775 * ciphertext: ciphertextWordArray,
776 * key: keyWordArray,
777 * iv: ivWordArray,
778 * salt: saltWordArray,
779 * algorithm: CryptoJS.algo.AES,
780 * mode: CryptoJS.mode.CBC,
781 * padding: CryptoJS.pad.PKCS7,
782 * blockSize: 4,
783 * formatter: CryptoJS.format.OpenSSL
784 * });
785 */
786 create(cipherParams: Partial<CipherParams>): CipherParams;
787 };
788
789 /**
790 * Abstract base stream cipher template.
791 */
792 interface StreamCipher extends Cipher {
793 /**
794 * The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
795 */
796 blockSize: number;
797 }
798
799 /**
800 * Abstract base block cipher mode template.
801 */
802 const BlockCipherMode: any;
803
804 /**
805 * A cipher wrapper that returns ciphertext as a serializable cipher params object.
806 */
807 const SerializableCipher: {
808 /**
809 * Encrypts a message.
810 *
811 * @param cipher The cipher algorithm to use.
812 * @param message The message to encrypt.
813 * @param key The key.
814 * @param cfg (Optional) The configuration options to use for this operation.
815 *
816 * @return A cipher params object.
817 *
818 * @example
819 *
820 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
821 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
822 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
823 */
824 encrypt(
825 cipher: CipherStatic,
826 message: WordArray | string,
827 key: WordArray,
828 cfg?: CipherOption,
829 ): CipherParams;
830
831 /**
832 * Decrypts serialized ciphertext.
833 *
834 * @param cipher The cipher algorithm to use.
835 * @param ciphertext The ciphertext to decrypt.
836 * @param key The key.
837 * @param cfg (Optional) The configuration options to use for this operation.
838 *
839 * @return The plaintext.
840 *
841 * @example
842 *
843 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
844 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
845 */
846 decrypt(
847 cipher: CipherStatic,
848 ciphertext: WordArray | string,
849 key: WordArray,
850 cfg?: CipherOption,
851 ): CipherParams;
852
853 /**
854 * Converts serialized ciphertext to CipherParams,
855 * else assumed CipherParams already and returns ciphertext unchanged.
856 *
857 * @param ciphertext The ciphertext.
858 * @param format The formatting strategy to use to parse serialized ciphertext.
859 *
860 * @return The unserialized ciphertext.
861 *
862 * @example
863 *
864 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
865 */
866 _parse(ciphertext: CipherParams | string, format: Format): CipherParams;
867 };
868
869 /**
870 * A serializable cipher wrapper that derives the key from a password,
871 * and returns ciphertext as a serializable cipher params object.
872 */
873 const PasswordBasedCipher: {
874 /**
875 * Encrypts a message using a password.
876 *
877 * @param cipher The cipher algorithm to use.
878 * @param message The message to encrypt.
879 * @param password The password.
880 * @param cfg (Optional) The configuration options to use for this operation.
881 *
882 * @return A cipher params object.
883 *
884 * @example
885 *
886 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
887 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
888 */
889 encrypt(
890 cipher: CipherStatic,
891 message: WordArray | string,
892 password: string,
893 cfg?: CipherOption,
894 ): CipherParams;
895
896 /**
897 * Decrypts serialized ciphertext using a password.
898 *
899 * @param cipher The cipher algorithm to use.
900 * @param ciphertext The ciphertext to decrypt.
901 * @param password The password.
902 * @param cfg (Optional) The configuration options to use for this operation.
903 *
904 * @return The plaintext.
905 *
906 * @example
907 *
908 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
909 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
910 */
911 decrypt(
912 cipher: CipherStatic,
913 ciphertext: CipherParams | string,
914 password: string,
915 cfg?: CipherOption,
916 ): WordArray;
917 };
918 }
919 /**
920 * Padding namespace.
921 */
922 export namespace pad {
923 /**
924 * PKCS #5/7 padding strategy.
925 */
926 const Pkcs7: Padding;
927
928 /**
929 * ANSI X.923 padding strategy.
930 */
931 const AnsiX923: Padding;
932
933 /**
934 * ISO 10126 padding strategy.
935 */
936 const Iso10126: Padding;
937
938 /**
939 * ISO/IEC 9797-1 Padding Method 2.
940 */
941 const Iso97971: Padding;
942
943 /**
944 * Zero padding strategy.
945 */
946 const ZeroPadding: Padding;
947
948 /**
949 * A noop padding strategy.
950 */
951 const NoPadding: Padding;
952 }
953
954 /**
955 * Key derivation function namespace.
956 */
957 export namespace kdf {
958 /**
959 * OpenSSL key derivation function.
960 */
961 const OpenSSL: {
962 /**
963 * Derives a key and IV from a password.
964 *
965 * @param password The password to derive from.
966 * @param keySize The size in words of the key to generate.
967 * @param ivSize The size in words of the IV to generate.
968 * @param salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
969 *
970 * @return A cipher params object with the key, IV, and salt.
971 *
972 * @example
973 *
974 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
975 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
976 */
977 execute(
978 password: string,
979 keySize: number,
980 ivSize: number,
981 salt?: WordArray | string,
982 hasher?: Hasher,
983 ): CipherParams;
984 };
985 }
986
987 /**
988 * Mode namespace.
989 */
990 export namespace mode {
991 /**
992 * Cipher Block Chaining mode.
993 */
994 const CBC: BlockCipherMode;
995
996 /**
997 * Cipher Feedback block mode.
998 */
999 const CFB: BlockCipherMode;
1000 /**
1001 * Counter block mode.
1002 */
1003 const CTR: BlockCipherMode;
1004 /**
1005 * @preserve
1006 * Counter block mode compatible with Dr Brian Gladman fileenc.c
1007 * derived from CryptoJS.mode.CTR
1008 * Jan Hruby jhruby.web@gmail.com
1009 */
1010 const CTRGladman: BlockCipherMode;
1011 /**
1012 * Output Feedback block mode.
1013 */
1014 const OFB: BlockCipherMode;
1015
1016 /**
1017 * Electronic Codebook block mode.
1018 */
1019 const ECB: BlockCipherMode;
1020 }
1021
1022 /**
1023 * Format namespace.
1024 */
1025 export namespace format {
1026 /**
1027 * OpenSSL formatting strategy.
1028 */
1029 const OpenSSL: Format;
1030 const Hex: Format;
1031 }
1032
1033 /**
1034 * Encoder namespace.
1035 */
1036 export namespace enc {
1037 /**
1038 * Hex encoding strategy.
1039 */
1040 const Hex: Encoder;
1041 /**
1042 * Latin1 encoding strategy.
1043 */
1044 const Latin1: Encoder;
1045 /**
1046 * UTF-8 encoding strategy.
1047 */
1048 const Utf8: Encoder;
1049 /**
1050 * UTF-16 BE encoding strategy.
1051 */
1052 const Utf16: Encoder;
1053 const Utf16BE: Encoder;
1054
1055 /**
1056 * UTF-16 LE encoding strategy.
1057 */
1058 const Utf16LE: Encoder;
1059 /**
1060 * Base64 encoding strategy.
1061 */
1062 const Base64: Encoder;
1063 /**
1064 * Base64url encoding strategy.
1065 */
1066 const Base64url: Encoder;
1067 }
1068
1069 /**
1070 * Algorithm namespace.
1071 */
1072 export namespace algo {
1073 /**
1074 * MD5 hash algorithm.
1075 */
1076 const MD5: HasherStatic;
1077
1078 /**
1079 * SHA-1 hash algorithm.
1080 */
1081 const SHA1: HasherStatic;
1082
1083 /**
1084 * SHA-256 hash algorithm.
1085 */
1086 const SHA256: HasherStatic;
1087 /**
1088 * SHA-224 hash algorithm.
1089 */
1090 const SHA224: HasherStatic;
1091 /**
1092 * SHA-512 hash algorithm.
1093 */
1094 const SHA512: HasherStatic;
1095
1096 /**
1097 * SHA-384 hash algorithm.
1098 */
1099 const SHA384: HasherStatic;
1100 /**
1101 * SHA-3 hash algorithm.
1102 */
1103 const SHA3: HasherStatic;
1104 /**
1105 * RIPEMD160 hash algorithm.
1106 */
1107 const RIPEMD160: HasherStatic;
1108 /**
1109 * HMAC algorithm.
1110 */
1111 abstract class HMAC {
1112 /**
1113 * Initializes a newly created HMAC.
1114 *
1115 * @param hasher The hash algorithm to use.
1116 * @param key The secret key.
1117 *
1118 * @example
1119 *
1120 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
1121 */
1122 static create(hasher: HasherStatic, key: WordArray | string): HMAC;
1123 /**
1124 * Resets this HMAC to its initial state.
1125 *
1126 * @example
1127 *
1128 * hmacHasher.reset();
1129 */
1130 reset(): void;
1131
1132 /**
1133 * Updates this HMAC with a message.
1134 *
1135 * @param messageUpdate The message to append.
1136 *
1137 * @return This HMAC instance.
1138 *
1139 * @example
1140 *
1141 * hmacHasher.update('message');
1142 * hmacHasher.update(wordArray);
1143 */
1144 update(messageUpdate: WordArray | string): this;
1145
1146 /**
1147 * Finalizes the HMAC computation.
1148 * Note that the finalize operation is effectively a destructive, read-once operation.
1149 *
1150 * @param messageUpdate (Optional) A final message update.
1151 *
1152 * @return The HMAC.
1153 *
1154 * @example
1155 *
1156 * var hmac = hmacHasher.finalize();
1157 * var hmac = hmacHasher.finalize('message');
1158 * var hmac = hmacHasher.finalize(wordArray);
1159 */
1160 finalize(messageUpdate?: WordArray | string): WordArray;
1161 }
1162 /**
1163 * Password-Based Key Derivation Function 2 algorithm.
1164 */
1165 abstract class PBKDF2 {
1166 /**
1167 * Initializes a newly created key derivation function.
1168 *
1169 * @param cfg (Optional) The configuration options to use for the derivation.
1170 *
1171 * @example
1172 *
1173 * var kdf = CryptoJS.algo.PBKDF2.create();
1174 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
1175 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
1176 */
1177 static create(cfg?: KDFOption): PBKDF2;
1178
1179 /**
1180 * Computes the Password-Based Key Derivation Function 2.
1181 *
1182 * @param password The password.
1183 * @param salt A salt.
1184 *
1185 * @return The derived key.
1186 *
1187 * @example
1188 *
1189 * var key = kdf.compute(password, salt);
1190 */
1191 compute(password: WordArray | string, salt: WordArray): WordArray;
1192 }
1193 /**
1194 * This key derivation function is meant to conform with EVP_BytesToKey.
1195 * www.openssl.org/docs/crypto/EVP_BytesToKey.html
1196 */
1197 abstract class EvpKDF {
1198 /**
1199 * Initializes a newly created key derivation function.
1200 *
1201 * @param cfg (Optional) The configuration options to use for the derivation.
1202 *
1203 * @example
1204 *
1205 * var kdf = CryptoJS.algo.EvpKDF.create();
1206 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
1207 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
1208 */
1209 static create(cfg?: { keySize: number; hasher?: HasherStatic | undefined; iterations: number }): EvpKDF;
1210
1211 /**
1212 * Derives a key from a password.
1213 *
1214 * @param password The password.
1215 * @param salt A salt.
1216 *
1217 * @return The derived key.
1218 *
1219 * @example
1220 *
1221 * var key = kdf.compute(password, salt);
1222 */
1223 compute(password: WordArray | string, salt: WordArray): WordArray;
1224 }
1225
1226 /**
1227 * AES block cipher algorithm.
1228 */
1229 const AES: CipherStatic;
1230
1231 /**
1232 * DES block cipher algorithm.
1233 */
1234 const DES: CipherStatic;
1235
1236 /**
1237 * Triple-DES block cipher algorithm.
1238 */
1239 const TripleDES: CipherStatic;
1240
1241 /**
1242 * RC4 stream cipher algorithm.
1243 */
1244 const RC4: CipherStatic;
1245
1246 /**
1247 * Modified RC4 stream cipher algorithm.
1248 */
1249 const RC4Drop: CipherStatic;
1250
1251 /**
1252 * Rabbit stream cipher algorithm
1253 */
1254 const Rabbit: CipherStatic;
1255
1256 /**
1257 * Rabbit stream cipher algorithm.
1258 *
1259 * This is a legacy version that neglected to convert the key to little-endian.
1260 * This error doesn't affect the cipher's security,
1261 * but it does affect its compatibility with other implementations.
1262 */
1263 const RabbitLegacy: CipherStatic;
1264 }
1265
1266 /**
1267 * x64 namespace.
1268 */
1269 export namespace x64 {
1270 /**
1271 * A 64-bit word.
1272 */
1273 interface Word {
1274 /**
1275 * Bitwise NOTs this word.
1276 *
1277 * @return A new x64-Word object after negating.
1278 *
1279 * @example
1280 *
1281 * var negated = x64Word.not();
1282 */
1283 not(): X64Word;
1284 /**
1285 * Bitwise ANDs this word with the passed word.
1286 *
1287 * @param word The x64-Word to AND with this word.
1288 *
1289 * @return A new x64-Word object after ANDing.
1290 *
1291 * @example
1292 *
1293 * var anded = x64Word.and(anotherX64Word);
1294 */
1295 and(word: X64Word): X64Word;
1296
1297 /**
1298 * Bitwise ORs this word with the passed word.
1299 *
1300 * @param word The x64-Word to OR with this word.
1301 *
1302 * @return A new x64-Word object after ORing.
1303 *
1304 * @example
1305 *
1306 * var ored = x64Word.or(anotherX64Word);
1307 */
1308 or(word: X64Word): X64Word;
1309
1310 /**
1311 * Bitwise XORs this word with the passed word.
1312 *
1313 * @param word The x64-Word to XOR with this word.
1314 *
1315 * @return A new x64-Word object after XORing.
1316 *
1317 * @example
1318 *
1319 * var xored = x64Word.xor(anotherX64Word);
1320 */
1321 xor(word: X64Word): X64Word;
1322 /**
1323 * Shifts this word n bits to the left.
1324 *
1325 * @param n The number of bits to shift.
1326 *
1327 * @return A new x64-Word object after shifting.
1328 *
1329 * @example
1330 *
1331 * var shifted = x64Word.shiftL(25);
1332 */
1333 shiftL(n: number): X64Word;
1334 /**
1335 * Shifts this word n bits to the right.
1336 *
1337 * @param n The number of bits to shift.
1338 *
1339 * @return A new x64-Word object after shifting.
1340 *
1341 * @example
1342 *
1343 * var shifted = x64Word.shiftR(7);
1344 */
1345 shiftR(n: number): X64Word;
1346 /**
1347 * Rotates this word n bits to the left.
1348 *
1349 * @param n The number of bits to rotate.
1350 *
1351 * @return A new x64-Word object after rotating.
1352 *
1353 * @example
1354 *
1355 * var rotated = x64Word.rotL(25);
1356 */
1357 rotL(n: number): X64Word;
1358
1359 /**
1360 * Rotates this word n bits to the right.
1361 *
1362 * @param n The number of bits to rotate.
1363 *
1364 * @return A new x64-Word object after rotating.
1365 *
1366 * @example
1367 *
1368 * var rotated = x64Word.rotR(7);
1369 */
1370 rotR(n: number): X64Word;
1371 /**
1372 * Adds this word with the passed word.
1373 *
1374 * @param word The x64-Word to add with this word.
1375 *
1376 * @return A new x64-Word object after adding.
1377 *
1378 * @example
1379 *
1380 * var added = x64Word.add(anotherX64Word);
1381 */
1382 add(word: X64Word): X64Word;
1383 }
1384
1385 const Word: {
1386 /**
1387 * Initializes a newly created 64-bit word.
1388 *
1389 * @param high The high 32 bits.
1390 * @param low The low 32 bits.
1391 *
1392 * @example
1393 *
1394 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
1395 */
1396 create(high: number, low: number): X64Word;
1397 };
1398
1399 /**
1400 * Initializes a newly created word array.
1401 *
1402 * @param words (Optional) An array of CryptoJS.x64.Word objects.
1403 * @param sigBytes (Optional) The number of significant bytes in the words.
1404 *
1405 * @example
1406 *
1407 * var wordArray = CryptoJS.x64.WordArray.create();
1408 *
1409 * var wordArray = CryptoJS.x64.WordArray.create([
1410 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1411 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1412 * ]);
1413 *
1414 * var wordArray = CryptoJS.x64.WordArray.create([
1415 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1416 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1417 * ], 10);
1418 */
1419 const WordArray: {
1420 create(words?: X64WordArray[], sigBytes?: number): X64WordArray;
1421 };
1422 }
1423
1424 /**
1425 * Shortcut function to the hasher's object interface.
1426 *
1427 * @param message The message to hash.
1428 *
1429 * @return The hash.
1430 *
1431 * @example
1432 *
1433 * var hash = CryptoJS.MD5('message');
1434 * var hash = CryptoJS.MD5(wordArray);
1435 */
1436 export const MD5: HasherHelper;
1437 /**
1438 * Shortcut function to the HMAC's object interface.
1439 *
1440 * @param message The message to hash.
1441 * @param key The secret key.
1442 *
1443 * @return The HMA'C.
1444 *
1445 * @example
1446 *
1447 * var hmac = CryptoJS.HmacMD5(message, key);
1448 */
1449 export const HmacMD5: HmacHasherHelper;
1450 /**
1451 * Shortcut function to the hasher's object interface.
1452 *
1453 * @param message The message to hash.
1454 *
1455 * @return The hash.
1456 *
1457 * @example
1458 *
1459 * var hash = CryptoJS.SHA1('message');
1460 * var hash = CryptoJS.SHA1(wordArray);
1461 */
1462 export const SHA1: HasherHelper;
1463 /**
1464 * Shortcut function to the HMAC's object interface.
1465 *
1466 * @param message The message to hash.
1467 * @param key The secret key.
1468 *
1469 * @return The HMAC.
1470 *
1471 * @example
1472 *
1473 * var hmac = CryptoJS.HmacSHA1(message, key);
1474 */
1475 export const HmacSHA1: HmacHasherHelper;
1476
1477 /**
1478 * Shortcut function to the hasher's object interface.
1479 *
1480 * @param message The message to hash.
1481 *
1482 * @return The hash.
1483 *
1484 * @example
1485 *
1486 * var hash = CryptoJS.SHA256('message');
1487 * var hash = CryptoJS.SHA256(wordArray);
1488 */
1489 export const SHA256: HasherHelper;
1490 /**
1491 * Shortcut function to the HMAC's object interface.
1492 *
1493 * @param message The message to hash.
1494 * @param key The secret key.
1495 *
1496 * @return The HMAC.
1497 *
1498 * @example
1499 *
1500 * var hmac = CryptoJS.HmacSHA256(message, key);
1501 */
1502 export const HmacSHA256: HmacHasherHelper;
1503 /**
1504 * Shortcut function to the hasher's object interface.
1505 *
1506 * @param message The message to hash.
1507 *
1508 * @return The hash.
1509 *
1510 * @example
1511 *
1512 * var hash = CryptoJS.SHA224('message');
1513 * var hash = CryptoJS.SHA224(wordArray);
1514 */
1515 export const SHA224: HasherHelper;
1516 /**
1517 * Shortcut function to the HMAC's object interface.
1518 *
1519 * @param message The message to hash.
1520 * @param key The secret key.
1521 *
1522 * @return The HMAC.
1523 *
1524 * @example
1525 *
1526 * var hmac = CryptoJS.HmacSHA224(message, key);
1527 */
1528 export const HmacSHA224: HmacHasherHelper;
1529 /**
1530 * Shortcut function to the hasher's object interface.
1531 *
1532 * @param message The message to hash.
1533 *
1534 * @return The hash.
1535 *
1536 * @example
1537 *
1538 * var hash = CryptoJS.SHA512('message');
1539 * var hash = CryptoJS.SHA512(wordArray);
1540 */
1541 export const SHA512: HasherHelper;
1542 /**
1543 * Shortcut function to the HMAC's object interface.
1544 *
1545 * @param message The message to hash.
1546 * @param key The secret key.
1547 *
1548 * @return The HMAC.
1549 *
1550 * @example
1551 *
1552 * var hmac = CryptoJS.HmacSHA512(message, key);
1553 */
1554 export const HmacSHA512: HmacHasherHelper;
1555 /**
1556 * Shortcut function to the hasher's object interface.
1557 *
1558 * @param message The message to hash.
1559 *
1560 * @return The hash.
1561 *
1562 * @example
1563 *
1564 * var hash = CryptoJS.SHA384('message');
1565 * var hash = CryptoJS.SHA384(wordArray);
1566 */
1567 export const SHA384: HasherHelper;
1568 /**
1569 * Shortcut function to the HMAC's object interface.
1570 *
1571 * @param message The message to hash.
1572 * @param key The secret key.
1573 *
1574 * @return The HMAC.
1575 *
1576 * @example
1577 *
1578 * var hmac = CryptoJS.HmacSHA384(message, key);
1579 */
1580 export const HmacSHA384: HmacHasherHelper;
1581
1582 /**
1583 * Shortcut function to the hasher's object interface.
1584 *
1585 * @param message The message to hash.
1586 *
1587 * @return The hash.
1588 *
1589 * @example
1590 *
1591 * var hash = CryptoJS.SHA3('message');
1592 * var hash = CryptoJS.SHA3(wordArray);
1593 */
1594 export const SHA3: HasherHelper;
1595 /**
1596 * Shortcut function to the HMAC's object interface.
1597 *
1598 * @param message The message to hash.
1599 * @param key The secret key.
1600 *
1601 * @return The HMAC.
1602 *
1603 * @example
1604 *
1605 * var hmac = CryptoJS.HmacSHA3(message, key);
1606 */
1607 export const HmacSHA3: HmacHasherHelper;
1608
1609 /**
1610 * Shortcut function to the hasher's object interface.
1611 *
1612 * @param message The message to hash.
1613 *
1614 * @return The hash.
1615 *
1616 * @example
1617 *
1618 * var hash = CryptoJS.RIPEMD160('message');
1619 * var hash = CryptoJS.RIPEMD160(wordArray);
1620 */
1621 export const RIPEMD160: HasherHelper;
1622 /**
1623 * Shortcut function to the HMAC's object interface.
1624 *
1625 * @param message The message to hash.
1626 * @param key The secret key.
1627 *
1628 * @return The HMAC.
1629 *
1630 * @example
1631 *
1632 * var hmac = CryptoJS.HmacRIPEMD160(message, key);
1633 */
1634 export const HmacRIPEMD160: HmacHasherHelper;
1635 /**
1636 * Computes the Password-Based Key Derivation Function 2.
1637 *
1638 * @param password The password.
1639 * @param salt A salt.
1640 * @param cfg (Optional) The configuration options to use for this computation.
1641 *
1642 * @return The derived key.
1643 *
1644 * @example
1645 *
1646 * var key = CryptoJS.PBKDF2(password, salt);
1647 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
1648 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
1649 */
1650 export function PBKDF2(password: WordArray | string, salt: WordArray | string, cfg?: KDFOption): WordArray;
1651
1652 /**
1653 * Shortcut functions to the cipher's object interface.
1654 *
1655 * @example
1656 *
1657 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
1658 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
1659 */
1660 export const AES: CipherHelper;
1661
1662 /**
1663 * Shortcut functions to the cipher's object interface.
1664 *
1665 * @example
1666 *
1667 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
1668 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
1669 */
1670 export const DES: CipherHelper;
1671
1672 /**
1673 * Shortcut functions to the cipher's object interface.
1674 *
1675 * @example
1676 *
1677 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
1678 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
1679 */
1680 export const TripleDES: CipherHelper;
1681
1682 /**
1683 * Shortcut functions to the cipher's object interface.
1684 *
1685 * @example
1686 *
1687 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
1688 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
1689 */
1690 export const RC4: CipherHelper;
1691
1692 /**
1693 * Shortcut functions to the cipher's object interface.
1694 *
1695 * @example
1696 *
1697 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
1698 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
1699 */
1700 export const RC4Drop: CipherHelper;
1701
1702 /**
1703 * Shortcut functions to the cipher's object interface.
1704 *
1705 * @example
1706 *
1707 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
1708 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
1709 */
1710 export const Rabbit: CipherHelper;
1711
1712 /**
1713 * Shortcut functions to the cipher's object interface.
1714 *
1715 * @example
1716 *
1717 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
1718 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
1719 */
1720 export const RabbitLegacy: CipherHelper;
1721
1722 /**
1723 * Shortcut functions to the cipher's object interface.
1724 *
1725 * @example
1726 *
1727 * var ciphertext = CryptoJS.Blowfish.encrypt(message, key, cfg);
1728 * var plaintext = CryptoJS.Blowfish.decrypt(ciphertext, key, cfg);
1729 */
1730 export const Blowfish: CipherHelper;
1731
1732 /**
1733 * Derives a key from a password.
1734 *
1735 * @param password The password.
1736 * @param salt A salt.
1737 * @param cfg (Optional) The configuration options to use for this computation.
1738 *
1739 * @return The derived key.
1740 *
1741 * @example
1742 *
1743 * var key = CryptoJS.EvpKDF(password, salt);
1744 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
1745 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
1746 */
1747 export function EvpKDF(
1748 password: WordArray | string,
1749 salt: WordArray | string,
1750 cfg?: {
1751 keySize: number;
1752 hasher?: HasherStatic | undefined;
1753 iterations: number;
1754 },
1755 ): WordArray;
1756 }
1757}