UNPKG

53.9 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(words?: number[], sigBytes?: number): WordArray;
637 /**
638 * Creates a word array filled with random bytes.
639 *
640 * @param nBytes The number of random bytes to generate.
641 *
642 * @return The random word array.
643 *
644 * @example
645 *
646 * var wordArray = CryptoJS.lib.WordArray.random(16);
647 */
648 random(nBytes: number): WordArray;
649 };
650
651 const BufferedBlockAlgorithm: any;
652
653 const Hasher: {
654 /**
655 * Creates a shortcut function to a hasher's object interface.
656 *
657 * @param hasher The hasher to create a helper for.
658 *
659 * @return The shortcut function.
660 *
661 * @example
662 *
663 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
664 */
665 _createHelper(hasher: HasherStatic): HasherHelper;
666 /**
667 * Creates a shortcut function to the HMAC's object interface.
668 *
669 * @param hasher The hasher to use in this HMAC helper.
670 *
671 * @return The shortcut function.
672 *
673 * @example
674 *
675 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
676 */
677 _createHmacHelper(hasher: HasherStatic): HmacHasherHelper;
678 };
679
680 const Cipher: {
681 /**
682 * Creates shortcut functions to a cipher's object interface.
683 *
684 * @param cipher The cipher to create a helper for.
685 *
686 * @return An object with encrypt and decrypt shortcut functions.
687 *
688 * @example
689 *
690 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
691 */
692 _createHelper(cipher: Cipher): CipherHelper;
693 };
694
695 /**
696 * A collection of cipher parameters.
697 */
698 interface CipherParams {
699 /**
700 * The raw ciphertext.
701 */
702 ciphertext: WordArray;
703 /**
704 * The key to this ciphertext.
705 */
706 key: WordArray;
707 /**
708 * The IV used in the ciphering operation.
709 */
710 iv: WordArray;
711 /**
712 * The salt used with a key derivation function.
713 */
714 salt: WordArray;
715 /**
716 * The cipher algorithm.
717 */
718 algorithm: CipherStatic;
719 /**
720 * The block mode used in the ciphering operation.
721 */
722 mode: Mode;
723 /**
724 * The padding scheme used in the ciphering operation.
725 */
726 padding: Padding;
727 /**
728 * The block size of the cipher.
729 */
730 blockSize: number;
731 /**
732 * The default formatting strategy to convert this cipher params object to a string.
733 */
734 formatter: Format;
735 /**
736 * Converts this cipher params object to a string.
737 *
738 * @param formatter (Optional) The formatting strategy to use.
739 *
740 * @return The stringified cipher params.
741 *
742 * @throws Error If neither the formatter nor the default formatter is set.
743 *
744 * @example
745 *
746 * var string = cipherParams + '';
747 * var string = cipherParams.toString();
748 * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
749 */
750 toString(formatter?: Format): string;
751 }
752 const CipherParams: {
753 /**
754 * Initializes a newly created cipher params object.
755 *
756 * @param cipherParams An object with any of the possible cipher parameters.
757 *
758 * @example
759 *
760 * var cipherParams = CryptoJS.lib.CipherParams.create({
761 * ciphertext: ciphertextWordArray,
762 * key: keyWordArray,
763 * iv: ivWordArray,
764 * salt: saltWordArray,
765 * algorithm: CryptoJS.algo.AES,
766 * mode: CryptoJS.mode.CBC,
767 * padding: CryptoJS.pad.PKCS7,
768 * blockSize: 4,
769 * formatter: CryptoJS.format.OpenSSL
770 * });
771 */
772 create(cipherParams: Partial<CipherParams>): CipherParams;
773 };
774
775 /**
776 * Abstract base stream cipher template.
777 */
778 interface StreamCipher extends Cipher {
779 /**
780 * The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
781 */
782 blockSize: number;
783 }
784
785 /**
786 * Abstract base block cipher mode template.
787 */
788 const BlockCipherMode: any;
789
790 /**
791 * A cipher wrapper that returns ciphertext as a serializable cipher params object.
792 */
793 const SerializableCipher: {
794 /**
795 * Encrypts a message.
796 *
797 * @param cipher The cipher algorithm to use.
798 * @param message The message to encrypt.
799 * @param key The key.
800 * @param cfg (Optional) The configuration options to use for this operation.
801 *
802 * @return A cipher params object.
803 *
804 * @example
805 *
806 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
807 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
808 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
809 */
810 encrypt(
811 cipher: CipherStatic,
812 message: WordArray | string,
813 key: WordArray,
814 cfg?: CipherOption,
815 ): CipherParams;
816
817 /**
818 * Decrypts serialized ciphertext.
819 *
820 * @param cipher The cipher algorithm to use.
821 * @param ciphertext The ciphertext to decrypt.
822 * @param key The key.
823 * @param cfg (Optional) The configuration options to use for this operation.
824 *
825 * @return The plaintext.
826 *
827 * @example
828 *
829 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
830 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
831 */
832 decrypt(
833 cipher: CipherStatic,
834 ciphertext: WordArray | string,
835 key: WordArray,
836 cfg?: CipherOption,
837 ): CipherParams;
838
839 /**
840 * Converts serialized ciphertext to CipherParams,
841 * else assumed CipherParams already and returns ciphertext unchanged.
842 *
843 * @param ciphertext The ciphertext.
844 * @param format The formatting strategy to use to parse serialized ciphertext.
845 *
846 * @return The unserialized ciphertext.
847 *
848 * @example
849 *
850 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
851 */
852 _parse(ciphertext: CipherParams | string, format: Format): CipherParams;
853 };
854
855 /**
856 * A serializable cipher wrapper that derives the key from a password,
857 * and returns ciphertext as a serializable cipher params object.
858 */
859 const PasswordBasedCipher: {
860 /**
861 * Encrypts a message using a password.
862 *
863 * @param cipher The cipher algorithm to use.
864 * @param message The message to encrypt.
865 * @param password The password.
866 * @param cfg (Optional) The configuration options to use for this operation.
867 *
868 * @return A cipher params object.
869 *
870 * @example
871 *
872 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
873 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
874 */
875 encrypt(
876 cipher: CipherStatic,
877 message: WordArray | string,
878 password: string,
879 cfg?: CipherOption,
880 ): CipherParams;
881
882 /**
883 * Decrypts serialized ciphertext using a password.
884 *
885 * @param cipher The cipher algorithm to use.
886 * @param ciphertext The ciphertext to decrypt.
887 * @param password The password.
888 * @param cfg (Optional) The configuration options to use for this operation.
889 *
890 * @return The plaintext.
891 *
892 * @example
893 *
894 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
895 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
896 */
897 decrypt(
898 cipher: CipherStatic,
899 ciphertext: CipherParams | string,
900 password: string,
901 cfg?: CipherOption,
902 ): WordArray;
903 };
904 }
905 /**
906 * Padding namespace.
907 */
908 export namespace pad {
909 /**
910 * PKCS #5/7 padding strategy.
911 */
912 const Pkcs7: Padding;
913
914 /**
915 * ANSI X.923 padding strategy.
916 */
917 const AnsiX923: Padding;
918
919 /**
920 * ISO 10126 padding strategy.
921 */
922 const Iso10126: Padding;
923
924 /**
925 * ISO/IEC 9797-1 Padding Method 2.
926 */
927 const Iso97971: Padding;
928
929 /**
930 * Zero padding strategy.
931 */
932 const ZeroPadding: Padding;
933
934 /**
935 * A noop padding strategy.
936 */
937 const NoPadding: Padding;
938 }
939
940 /**
941 * Key derivation function namespace.
942 */
943 export namespace kdf {
944 /**
945 * OpenSSL key derivation function.
946 */
947 const OpenSSL: {
948 /**
949 * Derives a key and IV from a password.
950 *
951 * @param password The password to derive from.
952 * @param keySize The size in words of the key to generate.
953 * @param ivSize The size in words of the IV to generate.
954 * @param salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
955 *
956 * @return A cipher params object with the key, IV, and salt.
957 *
958 * @example
959 *
960 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
961 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
962 */
963 execute(
964 password: string,
965 keySize: number,
966 ivSize: number,
967 salt?: WordArray | string,
968 hasher?: Hasher,
969 ): CipherParams;
970 };
971 }
972
973 /**
974 * Mode namespace.
975 */
976 export namespace mode {
977 /**
978 * Cipher Block Chaining mode.
979 */
980 const CBC: BlockCipherMode;
981
982 /**
983 * Cipher Feedback block mode.
984 */
985 const CFB: BlockCipherMode;
986 /**
987 * Counter block mode.
988 */
989 const CTR: BlockCipherMode;
990 /**
991 * @preserve
992 * Counter block mode compatible with Dr Brian Gladman fileenc.c
993 * derived from CryptoJS.mode.CTR
994 * Jan Hruby jhruby.web@gmail.com
995 */
996 const CTRGladman: BlockCipherMode;
997 /**
998 * Output Feedback block mode.
999 */
1000 const OFB: BlockCipherMode;
1001
1002 /**
1003 * Electronic Codebook block mode.
1004 */
1005 const ECB: BlockCipherMode;
1006 }
1007
1008 /**
1009 * Format namespace.
1010 */
1011 export namespace format {
1012 /**
1013 * OpenSSL formatting strategy.
1014 */
1015 const OpenSSL: Format;
1016 const Hex: Format;
1017 }
1018
1019 /**
1020 * Encoder namespace.
1021 */
1022 export namespace enc {
1023 /**
1024 * Hex encoding strategy.
1025 */
1026 const Hex: Encoder;
1027 /**
1028 * Latin1 encoding strategy.
1029 */
1030 const Latin1: Encoder;
1031 /**
1032 * UTF-8 encoding strategy.
1033 */
1034 const Utf8: Encoder;
1035 /**
1036 * UTF-16 BE encoding strategy.
1037 */
1038 const Utf16: Encoder;
1039 const Utf16BE: Encoder;
1040
1041 /**
1042 * UTF-16 LE encoding strategy.
1043 */
1044 const Utf16LE: Encoder;
1045 /**
1046 * Base64 encoding strategy.
1047 */
1048 const Base64: Encoder;
1049 /**
1050 * Base64url encoding strategy.
1051 */
1052 const Base64url: Encoder;
1053 }
1054
1055 /**
1056 * Algorithm namespace.
1057 */
1058 export namespace algo {
1059 /**
1060 * MD5 hash algorithm.
1061 */
1062 const MD5: HasherStatic;
1063
1064 /**
1065 * SHA-1 hash algorithm.
1066 */
1067 const SHA1: HasherStatic;
1068
1069 /**
1070 * SHA-256 hash algorithm.
1071 */
1072 const SHA256: HasherStatic;
1073 /**
1074 * SHA-224 hash algorithm.
1075 */
1076 const SHA224: HasherStatic;
1077 /**
1078 * SHA-512 hash algorithm.
1079 */
1080 const SHA512: HasherStatic;
1081
1082 /**
1083 * SHA-384 hash algorithm.
1084 */
1085 const SHA384: HasherStatic;
1086 /**
1087 * SHA-3 hash algorithm.
1088 */
1089 const SHA3: HasherStatic;
1090 /**
1091 * RIPEMD160 hash algorithm.
1092 */
1093 const RIPEMD160: HasherStatic;
1094 /**
1095 * HMAC algorithm.
1096 */
1097 abstract class HMAC {
1098 /**
1099 * Initializes a newly created HMAC.
1100 *
1101 * @param hasher The hash algorithm to use.
1102 * @param key The secret key.
1103 *
1104 * @example
1105 *
1106 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
1107 */
1108 static create(hasher: HasherStatic, key: WordArray | string): HMAC;
1109 /**
1110 * Resets this HMAC to its initial state.
1111 *
1112 * @example
1113 *
1114 * hmacHasher.reset();
1115 */
1116 reset(): void;
1117
1118 /**
1119 * Updates this HMAC with a message.
1120 *
1121 * @param messageUpdate The message to append.
1122 *
1123 * @return This HMAC instance.
1124 *
1125 * @example
1126 *
1127 * hmacHasher.update('message');
1128 * hmacHasher.update(wordArray);
1129 */
1130 update(messageUpdate: WordArray | string): this;
1131
1132 /**
1133 * Finalizes the HMAC computation.
1134 * Note that the finalize operation is effectively a destructive, read-once operation.
1135 *
1136 * @param messageUpdate (Optional) A final message update.
1137 *
1138 * @return The HMAC.
1139 *
1140 * @example
1141 *
1142 * var hmac = hmacHasher.finalize();
1143 * var hmac = hmacHasher.finalize('message');
1144 * var hmac = hmacHasher.finalize(wordArray);
1145 */
1146 finalize(messageUpdate?: WordArray | string): WordArray;
1147 }
1148 /**
1149 * Password-Based Key Derivation Function 2 algorithm.
1150 */
1151 abstract class PBKDF2 {
1152 /**
1153 * Initializes a newly created key derivation function.
1154 *
1155 * @param cfg (Optional) The configuration options to use for the derivation.
1156 *
1157 * @example
1158 *
1159 * var kdf = CryptoJS.algo.PBKDF2.create();
1160 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
1161 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
1162 */
1163 static create(cfg?: KDFOption): PBKDF2;
1164
1165 /**
1166 * Computes the Password-Based Key Derivation Function 2.
1167 *
1168 * @param password The password.
1169 * @param salt A salt.
1170 *
1171 * @return The derived key.
1172 *
1173 * @example
1174 *
1175 * var key = kdf.compute(password, salt);
1176 */
1177 compute(password: WordArray | string, salt: WordArray): WordArray;
1178 }
1179 /**
1180 * This key derivation function is meant to conform with EVP_BytesToKey.
1181 * www.openssl.org/docs/crypto/EVP_BytesToKey.html
1182 */
1183 abstract class EvpKDF {
1184 /**
1185 * Initializes a newly created key derivation function.
1186 *
1187 * @param cfg (Optional) The configuration options to use for the derivation.
1188 *
1189 * @example
1190 *
1191 * var kdf = CryptoJS.algo.EvpKDF.create();
1192 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
1193 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
1194 */
1195 static create(cfg?: { keySize: number; hasher?: HasherStatic | undefined; iterations: number }): EvpKDF;
1196
1197 /**
1198 * Derives a key from a password.
1199 *
1200 * @param password The password.
1201 * @param salt A salt.
1202 *
1203 * @return The derived key.
1204 *
1205 * @example
1206 *
1207 * var key = kdf.compute(password, salt);
1208 */
1209 compute(password: WordArray | string, salt: WordArray): WordArray;
1210 }
1211
1212 /**
1213 * AES block cipher algorithm.
1214 */
1215 const AES: CipherStatic;
1216
1217 /**
1218 * DES block cipher algorithm.
1219 */
1220 const DES: CipherStatic;
1221
1222 /**
1223 * Triple-DES block cipher algorithm.
1224 */
1225 const TripleDES: CipherStatic;
1226
1227 /**
1228 * RC4 stream cipher algorithm.
1229 */
1230 const RC4: CipherStatic;
1231
1232 /**
1233 * Modified RC4 stream cipher algorithm.
1234 */
1235 const RC4Drop: CipherStatic;
1236
1237 /**
1238 * Rabbit stream cipher algorithm
1239 */
1240 const Rabbit: CipherStatic;
1241
1242 /**
1243 * Rabbit stream cipher algorithm.
1244 *
1245 * This is a legacy version that neglected to convert the key to little-endian.
1246 * This error doesn't affect the cipher's security,
1247 * but it does affect its compatibility with other implementations.
1248 */
1249 const RabbitLegacy: CipherStatic;
1250 }
1251
1252 /**
1253 * x64 namespace.
1254 */
1255 export namespace x64 {
1256 /**
1257 * A 64-bit word.
1258 */
1259 interface Word {
1260 /**
1261 * Bitwise NOTs this word.
1262 *
1263 * @return A new x64-Word object after negating.
1264 *
1265 * @example
1266 *
1267 * var negated = x64Word.not();
1268 */
1269 not(): X64Word;
1270 /**
1271 * Bitwise ANDs this word with the passed word.
1272 *
1273 * @param word The x64-Word to AND with this word.
1274 *
1275 * @return A new x64-Word object after ANDing.
1276 *
1277 * @example
1278 *
1279 * var anded = x64Word.and(anotherX64Word);
1280 */
1281 and(word: X64Word): X64Word;
1282
1283 /**
1284 * Bitwise ORs this word with the passed word.
1285 *
1286 * @param word The x64-Word to OR with this word.
1287 *
1288 * @return A new x64-Word object after ORing.
1289 *
1290 * @example
1291 *
1292 * var ored = x64Word.or(anotherX64Word);
1293 */
1294 or(word: X64Word): X64Word;
1295
1296 /**
1297 * Bitwise XORs this word with the passed word.
1298 *
1299 * @param word The x64-Word to XOR with this word.
1300 *
1301 * @return A new x64-Word object after XORing.
1302 *
1303 * @example
1304 *
1305 * var xored = x64Word.xor(anotherX64Word);
1306 */
1307 xor(word: X64Word): X64Word;
1308 /**
1309 * Shifts this word n bits to the left.
1310 *
1311 * @param n The number of bits to shift.
1312 *
1313 * @return A new x64-Word object after shifting.
1314 *
1315 * @example
1316 *
1317 * var shifted = x64Word.shiftL(25);
1318 */
1319 shiftL(n: number): X64Word;
1320 /**
1321 * Shifts this word n bits to the right.
1322 *
1323 * @param n The number of bits to shift.
1324 *
1325 * @return A new x64-Word object after shifting.
1326 *
1327 * @example
1328 *
1329 * var shifted = x64Word.shiftR(7);
1330 */
1331 shiftR(n: number): X64Word;
1332 /**
1333 * Rotates this word n bits to the left.
1334 *
1335 * @param n The number of bits to rotate.
1336 *
1337 * @return A new x64-Word object after rotating.
1338 *
1339 * @example
1340 *
1341 * var rotated = x64Word.rotL(25);
1342 */
1343 rotL(n: number): X64Word;
1344
1345 /**
1346 * Rotates this word n bits to the right.
1347 *
1348 * @param n The number of bits to rotate.
1349 *
1350 * @return A new x64-Word object after rotating.
1351 *
1352 * @example
1353 *
1354 * var rotated = x64Word.rotR(7);
1355 */
1356 rotR(n: number): X64Word;
1357 /**
1358 * Adds this word with the passed word.
1359 *
1360 * @param word The x64-Word to add with this word.
1361 *
1362 * @return A new x64-Word object after adding.
1363 *
1364 * @example
1365 *
1366 * var added = x64Word.add(anotherX64Word);
1367 */
1368 add(word: X64Word): X64Word;
1369 }
1370
1371 const Word: {
1372 /**
1373 * Initializes a newly created 64-bit word.
1374 *
1375 * @param high The high 32 bits.
1376 * @param low The low 32 bits.
1377 *
1378 * @example
1379 *
1380 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
1381 */
1382 create(high: number, low: number): X64Word;
1383 };
1384
1385 /**
1386 * Initializes a newly created word array.
1387 *
1388 * @param words (Optional) An array of CryptoJS.x64.Word objects.
1389 * @param sigBytes (Optional) The number of significant bytes in the words.
1390 *
1391 * @example
1392 *
1393 * var wordArray = CryptoJS.x64.WordArray.create();
1394 *
1395 * var wordArray = CryptoJS.x64.WordArray.create([
1396 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1397 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1398 * ]);
1399 *
1400 * var wordArray = CryptoJS.x64.WordArray.create([
1401 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
1402 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
1403 * ], 10);
1404 */
1405 const WordArray: {
1406 create(words?: X64WordArray[], sigBytes?: number): X64WordArray;
1407 };
1408 }
1409
1410 /**
1411 * Shortcut function to the hasher's object interface.
1412 *
1413 * @param message The message to hash.
1414 *
1415 * @return The hash.
1416 *
1417 * @example
1418 *
1419 * var hash = CryptoJS.MD5('message');
1420 * var hash = CryptoJS.MD5(wordArray);
1421 */
1422 export const MD5: HasherHelper;
1423 /**
1424 * Shortcut function to the HMAC's object interface.
1425 *
1426 * @param message The message to hash.
1427 * @param key The secret key.
1428 *
1429 * @return The HMA'C.
1430 *
1431 * @example
1432 *
1433 * var hmac = CryptoJS.HmacMD5(message, key);
1434 */
1435 export const HmacMD5: HmacHasherHelper;
1436 /**
1437 * Shortcut function to the hasher's object interface.
1438 *
1439 * @param message The message to hash.
1440 *
1441 * @return The hash.
1442 *
1443 * @example
1444 *
1445 * var hash = CryptoJS.SHA1('message');
1446 * var hash = CryptoJS.SHA1(wordArray);
1447 */
1448 export const SHA1: HasherHelper;
1449 /**
1450 * Shortcut function to the HMAC's object interface.
1451 *
1452 * @param message The message to hash.
1453 * @param key The secret key.
1454 *
1455 * @return The HMAC.
1456 *
1457 * @example
1458 *
1459 * var hmac = CryptoJS.HmacSHA1(message, key);
1460 */
1461 export const HmacSHA1: HmacHasherHelper;
1462
1463 /**
1464 * Shortcut function to the hasher's object interface.
1465 *
1466 * @param message The message to hash.
1467 *
1468 * @return The hash.
1469 *
1470 * @example
1471 *
1472 * var hash = CryptoJS.SHA256('message');
1473 * var hash = CryptoJS.SHA256(wordArray);
1474 */
1475 export const SHA256: HasherHelper;
1476 /**
1477 * Shortcut function to the HMAC's object interface.
1478 *
1479 * @param message The message to hash.
1480 * @param key The secret key.
1481 *
1482 * @return The HMAC.
1483 *
1484 * @example
1485 *
1486 * var hmac = CryptoJS.HmacSHA256(message, key);
1487 */
1488 export const HmacSHA256: HmacHasherHelper;
1489 /**
1490 * Shortcut function to the hasher's object interface.
1491 *
1492 * @param message The message to hash.
1493 *
1494 * @return The hash.
1495 *
1496 * @example
1497 *
1498 * var hash = CryptoJS.SHA224('message');
1499 * var hash = CryptoJS.SHA224(wordArray);
1500 */
1501 export const SHA224: HasherHelper;
1502 /**
1503 * Shortcut function to the HMAC's object interface.
1504 *
1505 * @param message The message to hash.
1506 * @param key The secret key.
1507 *
1508 * @return The HMAC.
1509 *
1510 * @example
1511 *
1512 * var hmac = CryptoJS.HmacSHA224(message, key);
1513 */
1514 export const HmacSHA224: HmacHasherHelper;
1515 /**
1516 * Shortcut function to the hasher's object interface.
1517 *
1518 * @param message The message to hash.
1519 *
1520 * @return The hash.
1521 *
1522 * @example
1523 *
1524 * var hash = CryptoJS.SHA512('message');
1525 * var hash = CryptoJS.SHA512(wordArray);
1526 */
1527 export const SHA512: HasherHelper;
1528 /**
1529 * Shortcut function to the HMAC's object interface.
1530 *
1531 * @param message The message to hash.
1532 * @param key The secret key.
1533 *
1534 * @return The HMAC.
1535 *
1536 * @example
1537 *
1538 * var hmac = CryptoJS.HmacSHA512(message, key);
1539 */
1540 export const HmacSHA512: HmacHasherHelper;
1541 /**
1542 * Shortcut function to the hasher's object interface.
1543 *
1544 * @param message The message to hash.
1545 *
1546 * @return The hash.
1547 *
1548 * @example
1549 *
1550 * var hash = CryptoJS.SHA384('message');
1551 * var hash = CryptoJS.SHA384(wordArray);
1552 */
1553 export const SHA384: HasherHelper;
1554 /**
1555 * Shortcut function to the HMAC's object interface.
1556 *
1557 * @param message The message to hash.
1558 * @param key The secret key.
1559 *
1560 * @return The HMAC.
1561 *
1562 * @example
1563 *
1564 * var hmac = CryptoJS.HmacSHA384(message, key);
1565 */
1566 export const HmacSHA384: HmacHasherHelper;
1567
1568 /**
1569 * Shortcut function to the hasher's object interface.
1570 *
1571 * @param message The message to hash.
1572 *
1573 * @return The hash.
1574 *
1575 * @example
1576 *
1577 * var hash = CryptoJS.SHA3('message');
1578 * var hash = CryptoJS.SHA3(wordArray);
1579 */
1580 export const SHA3: HasherHelper;
1581 /**
1582 * Shortcut function to the HMAC's object interface.
1583 *
1584 * @param message The message to hash.
1585 * @param key The secret key.
1586 *
1587 * @return The HMAC.
1588 *
1589 * @example
1590 *
1591 * var hmac = CryptoJS.HmacSHA3(message, key);
1592 */
1593 export const HmacSHA3: HmacHasherHelper;
1594
1595 /**
1596 * Shortcut function to the hasher's object interface.
1597 *
1598 * @param message The message to hash.
1599 *
1600 * @return The hash.
1601 *
1602 * @example
1603 *
1604 * var hash = CryptoJS.RIPEMD160('message');
1605 * var hash = CryptoJS.RIPEMD160(wordArray);
1606 */
1607 export const RIPEMD160: HasherHelper;
1608 /**
1609 * Shortcut function to the HMAC's object interface.
1610 *
1611 * @param message The message to hash.
1612 * @param key The secret key.
1613 *
1614 * @return The HMAC.
1615 *
1616 * @example
1617 *
1618 * var hmac = CryptoJS.HmacRIPEMD160(message, key);
1619 */
1620 export const HmacRIPEMD160: HmacHasherHelper;
1621 /**
1622 * Computes the Password-Based Key Derivation Function 2.
1623 *
1624 * @param password The password.
1625 * @param salt A salt.
1626 * @param cfg (Optional) The configuration options to use for this computation.
1627 *
1628 * @return The derived key.
1629 *
1630 * @example
1631 *
1632 * var key = CryptoJS.PBKDF2(password, salt);
1633 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
1634 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
1635 */
1636 export function PBKDF2(password: WordArray | string, salt: WordArray | string, cfg?: KDFOption): WordArray;
1637
1638 /**
1639 * Shortcut functions to the cipher's object interface.
1640 *
1641 * @example
1642 *
1643 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
1644 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
1645 */
1646 export const AES: CipherHelper;
1647
1648 /**
1649 * Shortcut functions to the cipher's object interface.
1650 *
1651 * @example
1652 *
1653 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
1654 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
1655 */
1656 export const DES: CipherHelper;
1657
1658 /**
1659 * Shortcut functions to the cipher's object interface.
1660 *
1661 * @example
1662 *
1663 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
1664 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
1665 */
1666 export const TripleDES: CipherHelper;
1667
1668 /**
1669 * Shortcut functions to the cipher's object interface.
1670 *
1671 * @example
1672 *
1673 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
1674 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
1675 */
1676 export const RC4: CipherHelper;
1677
1678 /**
1679 * Shortcut functions to the cipher's object interface.
1680 *
1681 * @example
1682 *
1683 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
1684 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
1685 */
1686 export const RC4Drop: CipherHelper;
1687
1688 /**
1689 * Shortcut functions to the cipher's object interface.
1690 *
1691 * @example
1692 *
1693 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
1694 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
1695 */
1696 export const Rabbit: CipherHelper;
1697
1698 /**
1699 * Shortcut functions to the cipher's object interface.
1700 *
1701 * @example
1702 *
1703 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
1704 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
1705 */
1706 export const RabbitLegacy: CipherHelper;
1707
1708 /**
1709 * Shortcut functions to the cipher's object interface.
1710 *
1711 * @example
1712 *
1713 * var ciphertext = CryptoJS.Blowfish.encrypt(message, key, cfg);
1714 * var plaintext = CryptoJS.Blowfish.decrypt(ciphertext, key, cfg);
1715 */
1716 export const Blowfish: CipherHelper;
1717
1718 /**
1719 * Derives a key from a password.
1720 *
1721 * @param password The password.
1722 * @param salt A salt.
1723 * @param cfg (Optional) The configuration options to use for this computation.
1724 *
1725 * @return The derived key.
1726 *
1727 * @example
1728 *
1729 * var key = CryptoJS.EvpKDF(password, salt);
1730 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
1731 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
1732 */
1733 export function EvpKDF(
1734 password: WordArray | string,
1735 salt: WordArray | string,
1736 cfg?: {
1737 keySize: number;
1738 hasher?: HasherStatic | undefined;
1739 iterations: number;
1740 },
1741 ): WordArray;
1742 }
1743}