@tonysamperi/krypto 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/LICENCE +21 -0
  2. package/README.md +119 -0
  3. package/dist/cjs/algo/aes.class.d.cts +16 -0
  4. package/dist/cjs/algo/des.class.d.cts +19 -0
  5. package/dist/cjs/algo/index.d.cts +7 -0
  6. package/dist/cjs/algo/md5.class.d.cts +13 -0
  7. package/dist/cjs/algo/sha1.class.d.cts +9 -0
  8. package/dist/cjs/algo/sha256.class.d.cts +9 -0
  9. package/dist/cjs/algo/sha512.class.d.cts +9 -0
  10. package/dist/cjs/algo/triple-des.class.d.cts +16 -0
  11. package/dist/cjs/enc/base64.class.d.cts +31 -0
  12. package/dist/cjs/enc/encoder.model.d.cts +6 -0
  13. package/dist/cjs/enc/hex.class.d.cts +27 -0
  14. package/dist/cjs/enc/index.d.cts +6 -0
  15. package/dist/cjs/enc/latin1.class.d.cts +27 -0
  16. package/dist/cjs/enc/utf16.class.d.cts +28 -0
  17. package/dist/cjs/enc/utf8.class.d.cts +28 -0
  18. package/dist/cjs/format/formatter.interface.d.cts +5 -0
  19. package/dist/cjs/format/open-ssl.class.d.cts +27 -0
  20. package/dist/cjs/helpers/aes.helper.d.cts +2 -0
  21. package/dist/cjs/helpers/des.helper.d.cts +2 -0
  22. package/dist/cjs/helpers/index.d.cts +7 -0
  23. package/dist/cjs/helpers/md5.helper.d.cts +2 -0
  24. package/dist/cjs/helpers/sha1.helper.d.cts +2 -0
  25. package/dist/cjs/helpers/sha256.helper.d.cts +2 -0
  26. package/dist/cjs/helpers/sha512.helper.d.cts +2 -0
  27. package/dist/cjs/helpers/triple-des.helper.d.cts +2 -0
  28. package/dist/cjs/index.cjs +1 -0
  29. package/dist/cjs/index.d.cts +7 -0
  30. package/dist/cjs/kdf/evpkdf.class.d.cts +42 -0
  31. package/dist/cjs/kdf/index.d.cts +3 -0
  32. package/dist/cjs/kdf/kdf.model.d.cts +7 -0
  33. package/dist/cjs/kdf/open-ssl-kdf.class.d.cts +21 -0
  34. package/dist/cjs/kdf/pbkdf2.class.d.cts +18 -0
  35. package/dist/cjs/lib/block-cipher.class.d.cts +13 -0
  36. package/dist/cjs/lib/buffered-block-algorithm-config.interface.d.cts +13 -0
  37. package/dist/cjs/lib/buffered-block-algorithm.class.d.cts +54 -0
  38. package/dist/cjs/lib/cipher-helper.class.d.cts +10 -0
  39. package/dist/cjs/lib/cipher-params.class.d.cts +53 -0
  40. package/dist/cjs/lib/cipher.class.d.cts +112 -0
  41. package/dist/cjs/lib/hasher-constructor.type.d.cts +3 -0
  42. package/dist/cjs/lib/hasher-helper.type.d.cts +3 -0
  43. package/dist/cjs/lib/hasher.class.d.cts +58 -0
  44. package/dist/cjs/lib/hmac.class.d.cts +11 -0
  45. package/dist/cjs/lib/index.d.cts +8 -0
  46. package/dist/cjs/lib/password-based-cipher.class.d.cts +54 -0
  47. package/dist/cjs/lib/serializable-cipher.class.d.cts +73 -0
  48. package/dist/cjs/lib/word-array.class.d.cts +75 -0
  49. package/dist/cjs/lib/x64-word-array.class.d.cts +10 -0
  50. package/dist/cjs/lib/x64-word.class.d.cts +14 -0
  51. package/dist/cjs/mode/block-cipher-mode-algorithm.class.d.cts +20 -0
  52. package/dist/cjs/mode/block-cipher-mode.class.d.cts +28 -0
  53. package/dist/cjs/mode/cbc/cbc-decryptor.class.d.cts +17 -0
  54. package/dist/cjs/mode/cbc/cbc-encryptor.class.d.cts +17 -0
  55. package/dist/cjs/mode/cbc/cbc.class.d.cts +10 -0
  56. package/dist/cjs/mode/ctr/ctr-decryptor.class.d.cts +3 -0
  57. package/dist/cjs/mode/ctr/ctr-encryptor.class.d.cts +16 -0
  58. package/dist/cjs/mode/ctr/ctr.class.d.cts +10 -0
  59. package/dist/cjs/mode/ecb/ecb-decryptor.class.d.cts +14 -0
  60. package/dist/cjs/mode/ecb/ecb-encryptor.class.d.cts +14 -0
  61. package/dist/cjs/mode/ecb/ecb.class.d.cts +10 -0
  62. package/dist/cjs/mode/index.d.cts +11 -0
  63. package/dist/cjs/pad/index.d.cts +4 -0
  64. package/dist/cjs/pad/no-padding.class.d.cts +25 -0
  65. package/dist/cjs/pad/padding.model.d.cts +6 -0
  66. package/dist/cjs/pad/pkcs7.class.d.cts +25 -0
  67. package/dist/cjs/pad/zero-padding.class.d.cts +25 -0
  68. package/dist/esm/algo/aes.class.d.ts +16 -0
  69. package/dist/esm/algo/aes.class.js +138 -0
  70. package/dist/esm/algo/des.class.d.ts +19 -0
  71. package/dist/esm/algo/des.class.js +733 -0
  72. package/dist/esm/algo/index.d.ts +7 -0
  73. package/dist/esm/algo/index.js +7 -0
  74. package/dist/esm/algo/md5.class.d.ts +13 -0
  75. package/dist/esm/algo/md5.class.js +137 -0
  76. package/dist/esm/algo/sha1.class.d.ts +9 -0
  77. package/dist/esm/algo/sha1.class.js +66 -0
  78. package/dist/esm/algo/sha256.class.d.ts +9 -0
  79. package/dist/esm/algo/sha256.class.js +96 -0
  80. package/dist/esm/algo/sha512.class.d.ts +9 -0
  81. package/dist/esm/algo/sha512.class.js +221 -0
  82. package/dist/esm/algo/triple-des.class.d.ts +16 -0
  83. package/dist/esm/algo/triple-des.class.js +37 -0
  84. package/dist/esm/enc/base64.class.d.ts +31 -0
  85. package/dist/esm/enc/base64.class.js +80 -0
  86. package/dist/esm/enc/encoder.model.d.ts +6 -0
  87. package/dist/esm/enc/encoder.model.js +5 -0
  88. package/dist/esm/enc/hex.class.d.ts +27 -0
  89. package/dist/esm/enc/hex.class.js +45 -0
  90. package/dist/esm/enc/index.d.ts +6 -0
  91. package/dist/esm/enc/index.js +6 -0
  92. package/dist/esm/enc/latin1.class.d.ts +27 -0
  93. package/dist/esm/enc/latin1.class.js +44 -0
  94. package/dist/esm/enc/utf16.class.d.ts +28 -0
  95. package/dist/esm/enc/utf16.class.js +46 -0
  96. package/dist/esm/enc/utf8.class.d.ts +28 -0
  97. package/dist/esm/enc/utf8.class.js +39 -0
  98. package/dist/esm/format/formatter.interface.d.ts +5 -0
  99. package/dist/esm/format/formatter.interface.js +0 -0
  100. package/dist/esm/format/open-ssl.class.d.ts +27 -0
  101. package/dist/esm/format/open-ssl.class.js +57 -0
  102. package/dist/esm/helpers/aes.helper.d.ts +2 -0
  103. package/dist/esm/helpers/aes.helper.js +6 -0
  104. package/dist/esm/helpers/des.helper.d.ts +2 -0
  105. package/dist/esm/helpers/des.helper.js +6 -0
  106. package/dist/esm/helpers/index.d.ts +7 -0
  107. package/dist/esm/helpers/index.js +16 -0
  108. package/dist/esm/helpers/md5.helper.d.ts +2 -0
  109. package/dist/esm/helpers/md5.helper.js +6 -0
  110. package/dist/esm/helpers/sha1.helper.d.ts +2 -0
  111. package/dist/esm/helpers/sha1.helper.js +6 -0
  112. package/dist/esm/helpers/sha256.helper.d.ts +2 -0
  113. package/dist/esm/helpers/sha256.helper.js +6 -0
  114. package/dist/esm/helpers/sha512.helper.d.ts +2 -0
  115. package/dist/esm/helpers/sha512.helper.js +6 -0
  116. package/dist/esm/helpers/triple-des.helper.d.ts +2 -0
  117. package/dist/esm/helpers/triple-des.helper.js +6 -0
  118. package/dist/esm/index.d.ts +7 -0
  119. package/dist/esm/index.js +43 -0
  120. package/dist/esm/kdf/evpkdf.class.d.ts +42 -0
  121. package/dist/esm/kdf/evpkdf.class.js +59 -0
  122. package/dist/esm/kdf/index.d.ts +3 -0
  123. package/dist/esm/kdf/index.js +3 -0
  124. package/dist/esm/kdf/kdf.model.d.ts +7 -0
  125. package/dist/esm/kdf/kdf.model.js +5 -0
  126. package/dist/esm/kdf/open-ssl-kdf.class.d.ts +21 -0
  127. package/dist/esm/kdf/open-ssl-kdf.class.js +32 -0
  128. package/dist/esm/kdf/pbkdf2.class.d.ts +18 -0
  129. package/dist/esm/kdf/pbkdf2.class.js +43 -0
  130. package/dist/esm/lib/block-cipher.class.d.ts +13 -0
  131. package/dist/esm/lib/block-cipher.class.js +55 -0
  132. package/dist/esm/lib/buffered-block-algorithm-config.interface.d.ts +13 -0
  133. package/dist/esm/lib/buffered-block-algorithm-config.interface.js +0 -0
  134. package/dist/esm/lib/buffered-block-algorithm.class.d.ts +54 -0
  135. package/dist/esm/lib/buffered-block-algorithm.class.js +99 -0
  136. package/dist/esm/lib/cipher-helper.class.d.ts +10 -0
  137. package/dist/esm/lib/cipher-helper.class.js +24 -0
  138. package/dist/esm/lib/cipher-params.class.d.ts +53 -0
  139. package/dist/esm/lib/cipher-params.class.js +89 -0
  140. package/dist/esm/lib/cipher.class.d.ts +112 -0
  141. package/dist/esm/lib/cipher.class.js +112 -0
  142. package/dist/esm/lib/hasher-constructor.type.d.ts +3 -0
  143. package/dist/esm/lib/hasher-constructor.type.js +0 -0
  144. package/dist/esm/lib/hasher-helper.type.d.ts +3 -0
  145. package/dist/esm/lib/hasher-helper.type.js +0 -0
  146. package/dist/esm/lib/hasher.class.d.ts +58 -0
  147. package/dist/esm/lib/hasher.class.js +77 -0
  148. package/dist/esm/lib/hmac.class.d.ts +11 -0
  149. package/dist/esm/lib/hmac.class.js +39 -0
  150. package/dist/esm/lib/index.d.ts +8 -0
  151. package/dist/esm/lib/index.js +18 -0
  152. package/dist/esm/lib/password-based-cipher.class.d.ts +54 -0
  153. package/dist/esm/lib/password-based-cipher.class.js +92 -0
  154. package/dist/esm/lib/serializable-cipher.class.d.ts +73 -0
  155. package/dist/esm/lib/serializable-cipher.class.js +108 -0
  156. package/dist/esm/lib/word-array.class.d.ts +75 -0
  157. package/dist/esm/lib/word-array.class.js +123 -0
  158. package/dist/esm/lib/x64-word-array.class.d.ts +10 -0
  159. package/dist/esm/lib/x64-word-array.class.js +25 -0
  160. package/dist/esm/lib/x64-word.class.d.ts +14 -0
  161. package/dist/esm/lib/x64-word.class.js +47 -0
  162. package/dist/esm/mode/block-cipher-mode-algorithm.class.d.ts +20 -0
  163. package/dist/esm/mode/block-cipher-mode-algorithm.class.js +22 -0
  164. package/dist/esm/mode/block-cipher-mode.class.d.ts +28 -0
  165. package/dist/esm/mode/block-cipher-mode.class.js +36 -0
  166. package/dist/esm/mode/cbc/cbc-decryptor.class.d.ts +17 -0
  167. package/dist/esm/mode/cbc/cbc-decryptor.class.js +40 -0
  168. package/dist/esm/mode/cbc/cbc-encryptor.class.d.ts +17 -0
  169. package/dist/esm/mode/cbc/cbc-encryptor.class.js +39 -0
  170. package/dist/esm/mode/cbc/cbc.class.d.ts +10 -0
  171. package/dist/esm/mode/cbc/cbc.class.js +10 -0
  172. package/dist/esm/mode/ctr/ctr-decryptor.class.d.ts +3 -0
  173. package/dist/esm/mode/ctr/ctr-decryptor.class.js +6 -0
  174. package/dist/esm/mode/ctr/ctr-encryptor.class.d.ts +16 -0
  175. package/dist/esm/mode/ctr/ctr-encryptor.class.js +33 -0
  176. package/dist/esm/mode/ctr/ctr.class.d.ts +10 -0
  177. package/dist/esm/mode/ctr/ctr.class.js +10 -0
  178. package/dist/esm/mode/ecb/ecb-decryptor.class.d.ts +14 -0
  179. package/dist/esm/mode/ecb/ecb-decryptor.class.js +19 -0
  180. package/dist/esm/mode/ecb/ecb-encryptor.class.d.ts +14 -0
  181. package/dist/esm/mode/ecb/ecb-encryptor.class.js +19 -0
  182. package/dist/esm/mode/ecb/ecb.class.d.ts +10 -0
  183. package/dist/esm/mode/ecb/ecb.class.js +10 -0
  184. package/dist/esm/mode/index.d.ts +11 -0
  185. package/dist/esm/mode/index.js +24 -0
  186. package/dist/esm/pad/index.d.ts +4 -0
  187. package/dist/esm/pad/index.js +8 -0
  188. package/dist/esm/pad/no-padding.class.d.ts +25 -0
  189. package/dist/esm/pad/no-padding.class.js +28 -0
  190. package/dist/esm/pad/padding.model.d.ts +6 -0
  191. package/dist/esm/pad/padding.model.js +5 -0
  192. package/dist/esm/pad/pkcs7.class.d.ts +25 -0
  193. package/dist/esm/pad/pkcs7.class.js +40 -0
  194. package/dist/esm/pad/zero-padding.class.d.ts +25 -0
  195. package/dist/esm/pad/zero-padding.class.js +38 -0
  196. package/package.json +82 -0
@@ -0,0 +1,7 @@
1
+ import { WordArray } from "../lib/word-array.class.cjs";
2
+ import { CipherParams } from "../lib/cipher-params.class.cjs";
3
+ export declare abstract class AbstractKDF {
4
+ static execute: (password: string, keySize: number, ivSize: number, salt?: WordArray | string) => CipherParams;
5
+ abstract compute?(password: WordArray | string, salt: WordArray | string): WordArray;
6
+ }
7
+ export type KDF = typeof AbstractKDF;
@@ -0,0 +1,21 @@
1
+ import { WordArray } from "../lib/word-array.class.cjs";
2
+ import { CipherParams } from "../lib/cipher-params.class.cjs";
3
+ import { AbstractKDF } from "./kdf.model.cjs";
4
+ export declare class OpenSSLKdf implements AbstractKDF {
5
+ /**
6
+ * Derives a key and IV from a password.
7
+ *
8
+ * @param password The password to derive from.
9
+ * @param keySize The size in words of the key to generate.
10
+ * @param ivSize The size in words of the IV to generate.
11
+ * @param salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
12
+ *
13
+ * @return A cipher params object with the key, IV, and salt.
14
+ *
15
+ * @example
16
+ *
17
+ * let derivedParams = OpenSSL.execute('Password', 256/32, 128/32);
18
+ * let derivedParams = OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
19
+ */
20
+ static execute(password: string, keySize: number, ivSize: number, salt?: WordArray | string): CipherParams;
21
+ }
@@ -0,0 +1,18 @@
1
+ import { WordArray } from "../lib/word-array.class.cjs";
2
+ import { HasherConstructor } from "../lib/hasher-constructor.type.cjs";
3
+ import { AbstractKDF } from "./kdf.model.cjs";
4
+ export interface PBKDF2Config {
5
+ keySize: number;
6
+ hasher: HasherConstructor;
7
+ iterations: number;
8
+ }
9
+ export declare class PBKDF2 implements AbstractKDF {
10
+ cfg: PBKDF2Config;
11
+ constructor(cfg: Partial<PBKDF2Config>);
12
+ static execute(password: WordArray | string, salt: WordArray | string, cfg?: {
13
+ keySize?: number;
14
+ hasher?: HasherConstructor;
15
+ iterations?: number;
16
+ }): WordArray;
17
+ compute(password: WordArray | string, salt: WordArray | string): WordArray;
18
+ }
@@ -0,0 +1,13 @@
1
+ import { Cipher } from "./cipher.class.cjs";
2
+ import { WordArray } from "./word-array.class.cjs";
3
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
4
+ import { BlockCipherModeAlgorithm } from "../mode/block-cipher-mode-algorithm.class.cjs";
5
+ export declare abstract class BlockCipher extends Cipher {
6
+ protected _mode: BlockCipherModeAlgorithm;
7
+ constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig);
8
+ abstract decryptBlock(M: number[], offset: number): void;
9
+ abstract encryptBlock(M: number[], offset: number): void;
10
+ reset(): void;
11
+ protected _doFinalize(): WordArray;
12
+ protected _doProcessBlock(words: number[], offset: number): void;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { Formatter } from "../format/formatter.interface.cjs";
2
+ import { WordArray } from "./word-array.class.cjs";
3
+ import { KDF } from "../kdf/kdf.model.cjs";
4
+ import { BlockCipherMode } from "../mode/block-cipher-mode.class.cjs";
5
+ import { Padding } from "../pad/padding.model.cjs";
6
+ export interface BufferedBlockAlgorithmConfig {
7
+ blockSize?: number;
8
+ iv?: WordArray;
9
+ format?: Formatter;
10
+ kdf?: KDF;
11
+ mode?: typeof BlockCipherMode;
12
+ padding?: Padding;
13
+ }
@@ -0,0 +1,54 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
3
+ export declare abstract class BufferedBlockAlgorithm {
4
+ cfg: BufferedBlockAlgorithmConfig;
5
+ protected _data: WordArray;
6
+ protected _minBufferSize: number;
7
+ protected _nDataBytes: number;
8
+ protected abstract _doProcessBlock(wordArray: number[], offset: number): void;
9
+ constructor(cfg?: BufferedBlockAlgorithmConfig);
10
+ /**
11
+ * Creates a copy of this object.
12
+ *
13
+ * @return The clone.
14
+ *
15
+ * @example
16
+ *
17
+ * let clone = bufferedBlockAlgorithm.clone();
18
+ */
19
+ clone(): BufferedBlockAlgorithm;
20
+ /**
21
+ * Resets this block algorithm's data buffer to its initial state.
22
+ *
23
+ * @example
24
+ *
25
+ * bufferedBlockAlgorithm.reset();
26
+ */
27
+ reset(): void;
28
+ /**
29
+ * Adds new data to this block algorithm's buffer.
30
+ *
31
+ * @param data The data to append. Strings are converted to a WordArray using UTF-8.
32
+ *
33
+ * @example
34
+ *
35
+ * bufferedBlockAlgorithm._append('data');
36
+ * bufferedBlockAlgorithm._append(wordArray);
37
+ */
38
+ protected _append(data: string | WordArray): void;
39
+ /**
40
+ * Processes available data blocks.
41
+ *
42
+ * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
43
+ *
44
+ * @param doFlush Whether all blocks and partial blocks should be processed.
45
+ *
46
+ * @return The processed data.
47
+ *
48
+ * @example
49
+ *
50
+ * let processedData = bufferedBlockAlgorithm._process();
51
+ * let processedData = bufferedBlockAlgorithm._process(!!'flush');
52
+ */
53
+ protected _process(doFlush?: boolean): WordArray;
54
+ }
@@ -0,0 +1,10 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
3
+ import { CipherParams } from "./cipher-params.class.cjs";
4
+ import { Cipher } from "./cipher.class.cjs";
5
+ export declare class CipherHelper {
6
+ private readonly _cipher;
7
+ constructor(_cipher: typeof Cipher);
8
+ decrypt(ciphertext: CipherParams | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig): WordArray;
9
+ encrypt(message: WordArray | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig): CipherParams;
10
+ }
@@ -0,0 +1,53 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { Cipher } from "./cipher.class.cjs";
3
+ import { BlockCipherMode } from "../mode/block-cipher-mode.class.cjs";
4
+ import { Padding } from "../pad/padding.model.cjs";
5
+ import { Formatter } from "../format/formatter.interface.cjs";
6
+ export declare class CipherParams {
7
+ algorithm?: typeof Cipher;
8
+ blockSize?: number;
9
+ ciphertext?: WordArray;
10
+ formatter?: Formatter;
11
+ iv?: WordArray;
12
+ key?: WordArray | string;
13
+ mode?: typeof BlockCipherMode;
14
+ padding?: Padding;
15
+ salt?: WordArray | string;
16
+ /**
17
+ * Initializes a newly created cipher params object.
18
+ *
19
+ * @param cipherParams An object with any of the possible cipher parameters.
20
+ *
21
+ * @example
22
+ *
23
+ * let cipherParams = CipherParams.create({
24
+ * ciphertext: ciphertextWordArray,
25
+ * key: keyWordArray,
26
+ * iv: ivWordArray,
27
+ * salt: saltWordArray,
28
+ * algorithm: AES,
29
+ * mode: CBC,
30
+ * padding: PKCS7,
31
+ * blockSize: 4,
32
+ * formatter: OpenSSLFormatter
33
+ * });
34
+ */
35
+ constructor(cipherParams: Omit<CipherParams, "extend" | "toString">);
36
+ extend(additionalParams: CipherParams): CipherParams;
37
+ /**
38
+ * Converts this cipher params object to a string.
39
+ *
40
+ * @param formatter (Optional) The formatting strategy to use.
41
+ *
42
+ * @return The stringified cipher params.
43
+ *
44
+ * @throws Error If neither the formatter nor the default formatter is set.
45
+ *
46
+ * @example
47
+ *
48
+ * let string = cipherParams + '';
49
+ * let string = cipherParams.toString();
50
+ * let string = cipherParams.toString(CryptoJS.format.OpenSSL);
51
+ */
52
+ toString(formatter?: Formatter): string;
53
+ }
@@ -0,0 +1,112 @@
1
+ import { BufferedBlockAlgorithm } from "./buffered-block-algorithm.class.cjs";
2
+ import { WordArray } from "./word-array.class.cjs";
3
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
4
+ import { CipherHelper } from "./cipher-helper.class.cjs";
5
+ export declare abstract class Cipher extends BufferedBlockAlgorithm {
6
+ /**
7
+ * This cipher's IV size. Default: 4 (128 bits / 32 Bits)
8
+ */
9
+ static ivSize: number;
10
+ /**
11
+ * This cipher's key size. Default: 4 (128 bits / 32 Bits)
12
+ */
13
+ static keySize: number;
14
+ /**
15
+ * A constant representing decryption mode.
16
+ */
17
+ protected static readonly _DEC_XFORM_MODE = 2;
18
+ /**
19
+ * A constant representing encryption mode.
20
+ */
21
+ protected static readonly _ENC_XFORM_MODE = 1;
22
+ /**
23
+ * The key.
24
+ */
25
+ protected _key: WordArray;
26
+ /**
27
+ * Either the encryption or decryption transformation mode constant.
28
+ */
29
+ protected _xformMode: number;
30
+ /**
31
+ * Initializes a newly created cipher.
32
+ *
33
+ * @param xformMode Either the encryption or decryption transormation mode constant.
34
+ * @param key The key.
35
+ * @param cfg (Optional) The configuration options to use for this operation.
36
+ *
37
+ * @example
38
+ *
39
+ * let cipher = AES.create(AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
40
+ */
41
+ constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig);
42
+ /**
43
+ * Creates shortcut functions to a cipher's object interface.
44
+ *
45
+ * @param cipher The cipher to create a helper for.
46
+ *
47
+ * @return An object with encrypt and decrypt shortcut functions.
48
+ *
49
+ * @example
50
+ *
51
+ * const AES = Cipher._createHelper(AESAlgorithm);
52
+ */
53
+ static _createHelper(cipher: typeof Cipher): CipherHelper;
54
+ /**
55
+ * Creates this cipher in decryption mode.
56
+ *
57
+ * @param key The key.
58
+ * @param cfg (Optional) The configuration options to use for this operation.
59
+ *
60
+ * @return A cipher instance.
61
+ *
62
+ * @example
63
+ *
64
+ * let cipher = AES.createDecryptor(keyWordArray, { iv: ivWordArray });
65
+ */
66
+ static createDecryptor(key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig): Cipher;
67
+ /**
68
+ * Creates this cipher in encryption mode.
69
+ *
70
+ * @param key The key.
71
+ * @param cfg (Optional) The configuration options to use for this operation.
72
+ *
73
+ * @return A cipher instance.
74
+ *
75
+ * @example
76
+ *
77
+ * let cipher = AES.createEncryptor(keyWordArray, { iv: ivWordArray });
78
+ */
79
+ static createEncryptor(key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig): Cipher;
80
+ /**
81
+ * Finalizes the encryption or decryption process.
82
+ * Note that the finalize operation is effectively a destructive, read-once operation.
83
+ *
84
+ * @param dataUpdate The final data to encrypt or decrypt.
85
+ *
86
+ * @return The data after final processing.
87
+ *
88
+ * @example
89
+ *
90
+ * var encrypted = cipher.finalize();
91
+ * var encrypted = cipher.finalize('data');
92
+ * var encrypted = cipher.finalize(wordArray);
93
+ */
94
+ finalize(dataUpdate?: WordArray | string): WordArray;
95
+ /**
96
+ * Adds data to be encrypted or decrypted.
97
+ *
98
+ * @param dataUpdate The data to encrypt or decrypt.
99
+ *
100
+ * @return The data after processing.
101
+ *
102
+ * @example
103
+ *
104
+ * let encrypted = cipher.process('data');
105
+ * let encrypted = cipher.process(wordArray);
106
+ */
107
+ process(dataUpdate: WordArray | string): WordArray;
108
+ /**
109
+ * Cipher specific finalize function explicitly implemented in the derived class.
110
+ */
111
+ protected abstract _doFinalize(): WordArray;
112
+ }
@@ -0,0 +1,3 @@
1
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
2
+ import { Hasher } from "./hasher.class.cjs";
3
+ export type HasherConstructor<T extends Hasher = Hasher> = new (cfg?: BufferedBlockAlgorithmConfig) => T;
@@ -0,0 +1,3 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
3
+ export type HasherHelper = (message: WordArray | string, cfg?: BufferedBlockAlgorithmConfig) => WordArray;
@@ -0,0 +1,58 @@
1
+ import { BufferedBlockAlgorithm } from "./buffered-block-algorithm.class.cjs";
2
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
3
+ import { WordArray } from "./word-array.class.cjs";
4
+ import { HasherConstructor } from "./hasher-constructor.type.cjs";
5
+ import { HasherHelper } from "./hasher-helper.type.cjs";
6
+ export declare abstract class Hasher extends BufferedBlockAlgorithm {
7
+ /**
8
+ * Initializes a newly created hasher.
9
+ *
10
+ * @param cfg (Optional) The configuration options to use for this hash computation.
11
+ *
12
+ * @example
13
+ *
14
+ * let hasher = CryptoJS.algo.SHA256.create();
15
+ */
16
+ constructor(cfg?: BufferedBlockAlgorithmConfig);
17
+ /**
18
+ * Creates a shortcut function to the object interface of a hasher.
19
+ *
20
+ * @param hasher The hasher to create a helper for.
21
+ *
22
+ * @return The shortcut function.
23
+ *
24
+ * @example
25
+ *
26
+ * const SHA256 = Hasher._createHelper(SHA256);
27
+ */
28
+ static _createHelper<T extends Hasher = Hasher>(hasher: HasherConstructor<T>): HasherHelper;
29
+ protected abstract _doFinalize(): WordArray;
30
+ /**
31
+ * Finalizes the hash computation.
32
+ * Note that the finalize operation is effectively a destructive, read-once operation.
33
+ *
34
+ * @param messageUpdate (Optional) A final message update.
35
+ *
36
+ * @return The hash.
37
+ *
38
+ * @example
39
+ *
40
+ * let hash = hasher.finalize();
41
+ * let hash = hasher.finalize('message');
42
+ * let hash = hasher.finalize(wordArray);
43
+ */
44
+ finalize(messageUpdate?: WordArray | string): WordArray;
45
+ /**
46
+ * Updates this hasher with a message.
47
+ *
48
+ * @param messageUpdate The message to append.
49
+ *
50
+ * @return This hasher.
51
+ *
52
+ * @example
53
+ *
54
+ * hasher.update('message');
55
+ * hasher.update(wordArray);
56
+ */
57
+ update(messageUpdate: WordArray | string): Hasher;
58
+ }
@@ -0,0 +1,11 @@
1
+ import { HasherConstructor } from "./hasher-constructor.type.cjs";
2
+ import { WordArray } from "./word-array.class.cjs";
3
+ export declare class HMAC {
4
+ private _hasher;
5
+ private _iKey;
6
+ private _oKey;
7
+ constructor(hasher: HasherConstructor, rawKey: WordArray | string);
8
+ finalize(messageUpdate?: WordArray | string): WordArray;
9
+ reset(): void;
10
+ update(messageUpdate: WordArray | string): this;
11
+ }
@@ -0,0 +1,8 @@
1
+ export { BlockCipher } from "./block-cipher.class.cjs";
2
+ export { CipherParams } from "./cipher-params.class.cjs";
3
+ export { Hasher } from "./hasher.class.cjs";
4
+ export { PasswordBasedCipher } from "./password-based-cipher.class.cjs";
5
+ export { SerializableCipher } from "./serializable-cipher.class.cjs";
6
+ export { WordArray } from "./word-array.class.cjs";
7
+ export { X64Word } from "./x64-word.class.cjs";
8
+ export { X64WordArray } from "./x64-word-array.class.cjs";
@@ -0,0 +1,54 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { Cipher } from "./cipher.class.cjs";
3
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
4
+ import { CipherParams } from "./cipher-params.class.cjs";
5
+ import { Formatter } from "../format/formatter.interface.cjs";
6
+ export declare class PasswordBasedCipher {
7
+ static cfg: BufferedBlockAlgorithmConfig;
8
+ /**
9
+ * Decrypts serialized ciphertext using a password.
10
+ *
11
+ * @param cipher The cipher algorithm to use.
12
+ * @param ciphertext The ciphertext to decrypt.
13
+ * @param password The password.
14
+ * @param cfg (Optional) The configuration options to use for this operation.
15
+ *
16
+ * @return The plaintext.
17
+ *
18
+ * @example
19
+ *
20
+ * var plaintext = PasswordBasedCipher.decrypt(AES, formattedCiphertext, 'password', { format: OpenSSL });
21
+ * var plaintext = PasswordBasedCipher.decrypt(AES, ciphertextParams, 'password', { format: OpenSSL });
22
+ */
23
+ static decrypt(cipher: typeof Cipher, ciphertext: CipherParams | string, password: string, cfg?: BufferedBlockAlgorithmConfig): WordArray;
24
+ /**
25
+ * Encrypts a message using a password.
26
+ *
27
+ * @param cipher The cipher algorithm to use.
28
+ * @param message The message to encrypt.
29
+ * @param password The password.
30
+ * @param cfg (Optional) The configuration options to use for this operation.
31
+ *
32
+ * @return A cipher params object.
33
+ *
34
+ * @example
35
+ *
36
+ * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(AES, message, 'password');
37
+ * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(AES, message, 'password', { format: OpenSSL });
38
+ */
39
+ static encrypt(cipher: typeof Cipher, message: WordArray | string, password: string, cfg?: BufferedBlockAlgorithmConfig): CipherParams;
40
+ /**
41
+ * Converts serialized ciphertext to CipherParams,
42
+ * else assumed CipherParams already and returns ciphertext unchanged.
43
+ *
44
+ * @param ciphertext The ciphertext.
45
+ * @param format The formatting strategy to use to parse serialized ciphertext.
46
+ *
47
+ * @return The unserialized ciphertext.
48
+ *
49
+ * @example
50
+ *
51
+ * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
52
+ */
53
+ protected static _parse(ciphertext: CipherParams | string, format: Formatter): CipherParams;
54
+ }
@@ -0,0 +1,73 @@
1
+ import { WordArray } from "./word-array.class.cjs";
2
+ import { Cipher } from "./cipher.class.cjs";
3
+ import { BufferedBlockAlgorithmConfig } from "./buffered-block-algorithm-config.interface.cjs";
4
+ import { CipherParams } from "./cipher-params.class.cjs";
5
+ import { Formatter } from "../format/formatter.interface.cjs";
6
+ export declare class SerializableCipher {
7
+ static cfg: BufferedBlockAlgorithmConfig;
8
+ /**
9
+ * Decrypts serialized ciphertext.
10
+ *
11
+ * @param cipher The cipher algorithm to use.
12
+ * @param ciphertext The ciphertext to decrypt.
13
+ * @param key The key.
14
+ * @param optionalCfg The configuration options to use for this operation.
15
+ *
16
+ * @return The plaintext.
17
+ *
18
+ * @example
19
+ *
20
+ * let plaintext = SerializableCipher.decrypt(
21
+ * AESAlgorithm,
22
+ * formattedCiphertext,
23
+ * key, {
24
+ * iv: iv,
25
+ * format: CryptoJS.format.OpenSSL
26
+ * }
27
+ * );
28
+ *
29
+ * let plaintext = SerializableCipher.decrypt(
30
+ * AESAlgorithm,
31
+ * ciphertextParams,
32
+ * key, {
33
+ * iv: iv,
34
+ * format: CryptoJS.format.OpenSSL
35
+ * }
36
+ * );
37
+ */
38
+ static decrypt(cipher: typeof Cipher, ciphertext: CipherParams | string, key: WordArray | string, optionalCfg?: BufferedBlockAlgorithmConfig): WordArray;
39
+ /**
40
+ * Encrypts a message.
41
+ *
42
+ * @param cipher The cipher algorithm to use.
43
+ * @param message The message to encrypt.
44
+ * @param key The key.
45
+ * @param cfg (Optional) The configuration options to use for this operation.
46
+ *
47
+ * @return A cipher params object.
48
+ *
49
+ * @example
50
+ *
51
+ * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
52
+ * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
53
+ * let ciphertextParams = SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, {
54
+ * iv: iv,
55
+ * format: CryptoJS.format.OpenSSL
56
+ * });
57
+ */
58
+ static encrypt(cipher: typeof Cipher, message: WordArray | string, key: WordArray | string, cfg?: BufferedBlockAlgorithmConfig): CipherParams;
59
+ /**
60
+ * Converts serialized ciphertext to CipherParams,
61
+ * else assumed CipherParams already and returns ciphertext unchanged.
62
+ *
63
+ * @param ciphertext The ciphertext.
64
+ * @param format The formatting strategy to use to parse serialized ciphertext.
65
+ *
66
+ * @return The deserialized ciphertext.
67
+ *
68
+ * @example
69
+ *
70
+ * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
71
+ */
72
+ protected static _parse(ciphertext: CipherParams | string, format: Formatter): CipherParams;
73
+ }
@@ -0,0 +1,75 @@
1
+ export declare class WordArray {
2
+ sigBytes: number;
3
+ words: number[];
4
+ /**
5
+ * Initializes a newly created word array.
6
+ *
7
+ * @param words (Optional) An array of 32-bit words.
8
+ * @param sigBytes (Optional) The number of significant bytes in the words.
9
+ *
10
+ * @example
11
+ *
12
+ * let wordArray = new WordArray();
13
+ * let wordArray = new WordArray([0x00010203, 0x04050607]);
14
+ * let wordArray = new WordArray([0x00010203, 0x04050607], 6);
15
+ */
16
+ constructor(words?: number[], sigBytes?: number);
17
+ /**
18
+ * Creates a word array filled with random bytes.
19
+ *
20
+ * @param nBytes The number of random bytes to generate.
21
+ *
22
+ * @return The random word array.
23
+ *
24
+ * @example
25
+ *
26
+ * let wordArray = WordArray.random(16);
27
+ */
28
+ static random(nBytes: number): WordArray;
29
+ /**
30
+ * Removes insignificant bits.
31
+ *
32
+ * @example
33
+ *
34
+ * wordArray.clamp();
35
+ */
36
+ clamp(): void;
37
+ /**
38
+ * Creates a copy of this word array.
39
+ *
40
+ * @return The clone.
41
+ *
42
+ * @example
43
+ *
44
+ * let clone = wordArray.clone();
45
+ */
46
+ clone(): WordArray;
47
+ /**
48
+ * Concatenates a word array to this word array.
49
+ *
50
+ * @param wordArray The word array to append.
51
+ *
52
+ * @return This word array.
53
+ *
54
+ * @example
55
+ *
56
+ * wordArray1.concat(wordArray2);
57
+ */
58
+ concat(wordArray: WordArray): WordArray;
59
+ /**
60
+ * Converts this word array to a string.
61
+ *
62
+ * @param encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
63
+ *
64
+ * @return The stringified word array.
65
+ *
66
+ * @example
67
+ *
68
+ * let string = wordArray + '';
69
+ * let string = wordArray.toString();
70
+ * let string = wordArray.toString(CryptoJS.enc.Utf8);
71
+ */
72
+ toString<T extends {
73
+ stringify: (arg: WordArray) => string;
74
+ }>(encoder?: T): string;
75
+ }
@@ -0,0 +1,10 @@
1
+ import { X64Word } from "./x64-word.class.cjs";
2
+ import { WordArray } from "./word-array.class.cjs";
3
+ export declare class X64WordArray {
4
+ sigBytes: number;
5
+ words: X64Word[];
6
+ constructor(words?: X64Word[], sigBytes?: number);
7
+ static create(words?: X64Word[], sigBytes?: number): X64WordArray;
8
+ clone(): X64WordArray;
9
+ toX32(): WordArray;
10
+ }
@@ -0,0 +1,14 @@
1
+ export declare class X64Word {
2
+ high: number;
3
+ low: number;
4
+ constructor(high: number, low: number);
5
+ add(word: X64Word): X64Word;
6
+ and(word: X64Word): X64Word;
7
+ not(): X64Word;
8
+ or(word: X64Word): X64Word;
9
+ rotL(n: number): X64Word;
10
+ rotR(n: number): X64Word;
11
+ shiftL(n: number): X64Word;
12
+ shiftR(n: number): X64Word;
13
+ xor(word: X64Word): X64Word;
14
+ }
@@ -0,0 +1,20 @@
1
+ import { BlockCipher } from "../lib/block-cipher.class.cjs";
2
+ import { BlockCipherMode } from "./block-cipher-mode.class.cjs";
3
+ export declare abstract class BlockCipherModeAlgorithm {
4
+ __creator: ((cipher: BlockCipher, iv: number[]) => BlockCipherMode) | undefined;
5
+ protected _cipher: BlockCipher;
6
+ protected _iv: number[] | undefined;
7
+ constructor(cipher: BlockCipher, iv: number[]);
8
+ abstract processBlock(words: number[], offset: number): void;
9
+ /**
10
+ * Initializes a newly created mode.
11
+ *
12
+ * @param cipher A block cipher instance.
13
+ * @param iv The IV words.
14
+ *
15
+ * @example
16
+ *
17
+ * var mode = CBC.Encryptor.create(cipher, iv.words);
18
+ */
19
+ init(cipher: BlockCipher, iv?: number[]): void;
20
+ }