@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
+ export * from "./aes.class.js";
2
+ export * from "./des.class.js";
3
+ export * from "./md5.class.js";
4
+ export * from "./triple-des.class.js";
5
+ export * from "./sha1.class.js";
6
+ export * from "./sha256.class.js";
7
+ export * from "./sha512.class.js";
@@ -0,0 +1,13 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ export declare class MD5 extends Hasher {
4
+ get hash(): WordArray;
5
+ protected _hash: WordArray;
6
+ static FF(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number;
7
+ static GG(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number;
8
+ static HH(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number;
9
+ static II(a: number, b: number, c: number, d: number, x: number, s: number, t: number): number;
10
+ reset(): void;
11
+ protected _doFinalize(): WordArray;
12
+ protected _doProcessBlock(m: number[], offset: number): void;
13
+ }
@@ -0,0 +1,137 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ const T = [];
4
+ for (let i = 0; i < 64; i++) {
5
+ T[i] = Math.abs(Math.sin(i + 1)) * 4294967296 | 0;
6
+ }
7
+ class MD5 extends Hasher {
8
+ get hash() {
9
+ return this._hash;
10
+ }
11
+ static FF(a, b, c, d, x, s, t) {
12
+ const n = a + (b & c | ~b & d) + x + t;
13
+ return (n << s | n >>> 32 - s) + b;
14
+ }
15
+ static GG(a, b, c, d, x, s, t) {
16
+ const n = a + (b & d | c & ~d) + x + t;
17
+ return (n << s | n >>> 32 - s) + b;
18
+ }
19
+ static HH(a, b, c, d, x, s, t) {
20
+ const n = a + (b ^ c ^ d) + x + t;
21
+ return (n << s | n >>> 32 - s) + b;
22
+ }
23
+ static II(a, b, c, d, x, s, t) {
24
+ const n = a + (c ^ (b | ~d)) + x + t;
25
+ return (n << s | n >>> 32 - s) + b;
26
+ }
27
+ reset() {
28
+ super.reset();
29
+ this._hash = new WordArray([
30
+ 1732584193,
31
+ 4023233417,
32
+ 2562383102,
33
+ 271733878
34
+ ]);
35
+ }
36
+ _doFinalize() {
37
+ const nBitsTotal = this._nDataBytes * 8;
38
+ const nBitsLeft = this._data.sigBytes * 8;
39
+ this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
40
+ const nBitsTotalH = Math.floor(nBitsTotal / 4294967296);
41
+ const nBitsTotalL = nBitsTotal;
42
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = (nBitsTotalH << 8 | nBitsTotalH >>> 24) & 16711935 | (nBitsTotalH << 24 | nBitsTotalH >>> 8) & 4278255360;
43
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = (nBitsTotalL << 8 | nBitsTotalL >>> 24) & 16711935 | (nBitsTotalL << 24 | nBitsTotalL >>> 8) & 4278255360;
44
+ this._data.sigBytes = (this._data.words.length + 1) * 4;
45
+ this._process();
46
+ for (let i = 0; i < 4; i++) {
47
+ this._hash.words[i] = (this._hash.words[i] << 8 | this._hash.words[i] >>> 24) & 16711935 | (this._hash.words[i] << 24 | this._hash.words[i] >>> 8) & 4278255360;
48
+ }
49
+ return this._hash;
50
+ }
51
+ _doProcessBlock(m, offset) {
52
+ for (let i = 0; i < 16; i++) {
53
+ const offsetI = offset + i;
54
+ const mOffsetI = m[offsetI];
55
+ m[offsetI] = (mOffsetI << 8 | mOffsetI >>> 24) & 16711935 | (mOffsetI << 24 | mOffsetI >>> 8) & 4278255360;
56
+ }
57
+ const mOffsets = Array.from({ length: 16 });
58
+ for (let i = 0; i < 16; i++) {
59
+ mOffsets[i] = m[offset + i];
60
+ }
61
+ let a = this._hash.words[0];
62
+ let b = this._hash.words[1];
63
+ let c = this._hash.words[2];
64
+ let d = this._hash.words[3];
65
+ a = MD5.FF(a, b, c, d, mOffsets[0], 7, T[0]);
66
+ d = MD5.FF(d, a, b, c, mOffsets[1], 12, T[1]);
67
+ c = MD5.FF(c, d, a, b, mOffsets[2], 17, T[2]);
68
+ b = MD5.FF(b, c, d, a, mOffsets[3], 22, T[3]);
69
+ a = MD5.FF(a, b, c, d, mOffsets[4], 7, T[4]);
70
+ d = MD5.FF(d, a, b, c, mOffsets[5], 12, T[5]);
71
+ c = MD5.FF(c, d, a, b, mOffsets[6], 17, T[6]);
72
+ b = MD5.FF(b, c, d, a, mOffsets[7], 22, T[7]);
73
+ a = MD5.FF(a, b, c, d, mOffsets[8], 7, T[8]);
74
+ d = MD5.FF(d, a, b, c, mOffsets[9], 12, T[9]);
75
+ c = MD5.FF(c, d, a, b, mOffsets[10], 17, T[10]);
76
+ b = MD5.FF(b, c, d, a, mOffsets[11], 22, T[11]);
77
+ a = MD5.FF(a, b, c, d, mOffsets[12], 7, T[12]);
78
+ d = MD5.FF(d, a, b, c, mOffsets[13], 12, T[13]);
79
+ c = MD5.FF(c, d, a, b, mOffsets[14], 17, T[14]);
80
+ b = MD5.FF(b, c, d, a, mOffsets[15], 22, T[15]);
81
+ a = MD5.GG(a, b, c, d, mOffsets[1], 5, T[16]);
82
+ d = MD5.GG(d, a, b, c, mOffsets[6], 9, T[17]);
83
+ c = MD5.GG(c, d, a, b, mOffsets[11], 14, T[18]);
84
+ b = MD5.GG(b, c, d, a, mOffsets[0], 20, T[19]);
85
+ a = MD5.GG(a, b, c, d, mOffsets[5], 5, T[20]);
86
+ d = MD5.GG(d, a, b, c, mOffsets[10], 9, T[21]);
87
+ c = MD5.GG(c, d, a, b, mOffsets[15], 14, T[22]);
88
+ b = MD5.GG(b, c, d, a, mOffsets[4], 20, T[23]);
89
+ a = MD5.GG(a, b, c, d, mOffsets[9], 5, T[24]);
90
+ d = MD5.GG(d, a, b, c, mOffsets[14], 9, T[25]);
91
+ c = MD5.GG(c, d, a, b, mOffsets[3], 14, T[26]);
92
+ b = MD5.GG(b, c, d, a, mOffsets[8], 20, T[27]);
93
+ a = MD5.GG(a, b, c, d, mOffsets[13], 5, T[28]);
94
+ d = MD5.GG(d, a, b, c, mOffsets[2], 9, T[29]);
95
+ c = MD5.GG(c, d, a, b, mOffsets[7], 14, T[30]);
96
+ b = MD5.GG(b, c, d, a, mOffsets[12], 20, T[31]);
97
+ a = MD5.HH(a, b, c, d, mOffsets[5], 4, T[32]);
98
+ d = MD5.HH(d, a, b, c, mOffsets[8], 11, T[33]);
99
+ c = MD5.HH(c, d, a, b, mOffsets[11], 16, T[34]);
100
+ b = MD5.HH(b, c, d, a, mOffsets[14], 23, T[35]);
101
+ a = MD5.HH(a, b, c, d, mOffsets[1], 4, T[36]);
102
+ d = MD5.HH(d, a, b, c, mOffsets[4], 11, T[37]);
103
+ c = MD5.HH(c, d, a, b, mOffsets[7], 16, T[38]);
104
+ b = MD5.HH(b, c, d, a, mOffsets[10], 23, T[39]);
105
+ a = MD5.HH(a, b, c, d, mOffsets[13], 4, T[40]);
106
+ d = MD5.HH(d, a, b, c, mOffsets[0], 11, T[41]);
107
+ c = MD5.HH(c, d, a, b, mOffsets[3], 16, T[42]);
108
+ b = MD5.HH(b, c, d, a, mOffsets[6], 23, T[43]);
109
+ a = MD5.HH(a, b, c, d, mOffsets[9], 4, T[44]);
110
+ d = MD5.HH(d, a, b, c, mOffsets[12], 11, T[45]);
111
+ c = MD5.HH(c, d, a, b, mOffsets[15], 16, T[46]);
112
+ b = MD5.HH(b, c, d, a, mOffsets[2], 23, T[47]);
113
+ a = MD5.II(a, b, c, d, mOffsets[0], 6, T[48]);
114
+ d = MD5.II(d, a, b, c, mOffsets[7], 10, T[49]);
115
+ c = MD5.II(c, d, a, b, mOffsets[14], 15, T[50]);
116
+ b = MD5.II(b, c, d, a, mOffsets[5], 21, T[51]);
117
+ a = MD5.II(a, b, c, d, mOffsets[12], 6, T[52]);
118
+ d = MD5.II(d, a, b, c, mOffsets[3], 10, T[53]);
119
+ c = MD5.II(c, d, a, b, mOffsets[10], 15, T[54]);
120
+ b = MD5.II(b, c, d, a, mOffsets[1], 21, T[55]);
121
+ a = MD5.II(a, b, c, d, mOffsets[8], 6, T[56]);
122
+ d = MD5.II(d, a, b, c, mOffsets[15], 10, T[57]);
123
+ c = MD5.II(c, d, a, b, mOffsets[6], 15, T[58]);
124
+ b = MD5.II(b, c, d, a, mOffsets[13], 21, T[59]);
125
+ a = MD5.II(a, b, c, d, mOffsets[4], 6, T[60]);
126
+ d = MD5.II(d, a, b, c, mOffsets[11], 10, T[61]);
127
+ c = MD5.II(c, d, a, b, mOffsets[2], 15, T[62]);
128
+ b = MD5.II(b, c, d, a, mOffsets[9], 21, T[63]);
129
+ this._hash.words[0] = this._hash.words[0] + a | 0;
130
+ this._hash.words[1] = this._hash.words[1] + b | 0;
131
+ this._hash.words[2] = this._hash.words[2] + c | 0;
132
+ this._hash.words[3] = this._hash.words[3] + d | 0;
133
+ }
134
+ }
135
+ export {
136
+ MD5
137
+ };
@@ -0,0 +1,9 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ export declare class SHA1 extends Hasher {
4
+ get hash(): WordArray;
5
+ protected _hash: WordArray;
6
+ reset(): void;
7
+ protected _doFinalize(): WordArray;
8
+ protected _doProcessBlock(m: number[], offset: number): void;
9
+ }
@@ -0,0 +1,66 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ const H = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4
+ const W = new Array(80);
5
+ class SHA1 extends Hasher {
6
+ get hash() {
7
+ return this._hash;
8
+ }
9
+ reset() {
10
+ super.reset();
11
+ this._hash = new WordArray(H.slice(0));
12
+ }
13
+ _doFinalize() {
14
+ const nBitsTotal = this._nDataBytes * 8;
15
+ const nBitsLeft = this._data.sigBytes * 8;
16
+ this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
17
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
18
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
19
+ this._data.sigBytes = this._data.words.length * 4;
20
+ this._process();
21
+ return this._hash;
22
+ }
23
+ _doProcessBlock(m, offset) {
24
+ let a = this._hash.words[0];
25
+ let b = this._hash.words[1];
26
+ let c = this._hash.words[2];
27
+ let d = this._hash.words[3];
28
+ let e = this._hash.words[4];
29
+ for (let i = 0; i < 80; i++) {
30
+ if (i < 16) {
31
+ W[i] = m[offset + i] | 0;
32
+ } else {
33
+ const n = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16];
34
+ W[i] = n << 1 | n >>> 31;
35
+ }
36
+ let f, k;
37
+ if (i < 20) {
38
+ f = b & c | ~b & d;
39
+ k = 1518500249;
40
+ } else if (i < 40) {
41
+ f = b ^ c ^ d;
42
+ k = 1859775393;
43
+ } else if (i < 60) {
44
+ f = b & c | b & d | c & d;
45
+ k = 2400959708;
46
+ } else {
47
+ f = b ^ c ^ d;
48
+ k = 3395469782;
49
+ }
50
+ const temp = (a << 5 | a >>> 27) + f + e + k + W[i];
51
+ e = d;
52
+ d = c;
53
+ c = b << 30 | b >>> 2;
54
+ b = a;
55
+ a = temp | 0;
56
+ }
57
+ this._hash.words[0] = this._hash.words[0] + a | 0;
58
+ this._hash.words[1] = this._hash.words[1] + b | 0;
59
+ this._hash.words[2] = this._hash.words[2] + c | 0;
60
+ this._hash.words[3] = this._hash.words[3] + d | 0;
61
+ this._hash.words[4] = this._hash.words[4] + e | 0;
62
+ }
63
+ }
64
+ export {
65
+ SHA1
66
+ };
@@ -0,0 +1,9 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ export declare class SHA256 extends Hasher {
4
+ private _hash;
5
+ constructor();
6
+ reset(): void;
7
+ protected _doFinalize(): WordArray;
8
+ protected _doProcessBlock(m: number[], offset: number): void;
9
+ }
@@ -0,0 +1,96 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ const H = [];
4
+ const K = [];
5
+ (function() {
6
+ function isPrime(n2) {
7
+ const sqrtN = Math.sqrt(n2);
8
+ for (let factor = 2; factor <= sqrtN; factor++) {
9
+ if (!(n2 % factor)) {
10
+ return false;
11
+ }
12
+ }
13
+ return true;
14
+ }
15
+ function getFractionalBits(n2) {
16
+ return (n2 - (n2 | 0)) * 4294967296 | 0;
17
+ }
18
+ let n = 2;
19
+ let nPrime = 0;
20
+ while (nPrime < 64) {
21
+ if (isPrime(n)) {
22
+ if (nPrime < 8) {
23
+ H[nPrime] = getFractionalBits(Math.pow(n, 1 / 2));
24
+ }
25
+ K[nPrime] = getFractionalBits(Math.pow(n, 1 / 3));
26
+ nPrime++;
27
+ }
28
+ n++;
29
+ }
30
+ })();
31
+ const W = [];
32
+ class SHA256 extends Hasher {
33
+ constructor() {
34
+ super();
35
+ }
36
+ reset() {
37
+ super.reset();
38
+ this._hash = new WordArray(H.slice(0));
39
+ }
40
+ _doFinalize() {
41
+ const nBitsTotal = this._nDataBytes * 8;
42
+ const nBitsLeft = this._data.sigBytes * 8;
43
+ this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
44
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
45
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
46
+ this._data.sigBytes = this._data.words.length * 4;
47
+ this._process();
48
+ return this._hash;
49
+ }
50
+ _doProcessBlock(m, offset) {
51
+ let a = this._hash.words[0];
52
+ let b = this._hash.words[1];
53
+ let c = this._hash.words[2];
54
+ let d = this._hash.words[3];
55
+ let e = this._hash.words[4];
56
+ let f = this._hash.words[5];
57
+ let g = this._hash.words[6];
58
+ let h = this._hash.words[7];
59
+ for (let i = 0; i < 64; i++) {
60
+ if (i < 16) {
61
+ W[i] = m[offset + i] | 0;
62
+ } else {
63
+ const gamma0x = W[i - 15];
64
+ const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
65
+ const gamma1x = W[i - 2];
66
+ const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
67
+ W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
68
+ }
69
+ const ch = e & f ^ ~e & g;
70
+ const maj = a & b ^ a & c ^ b & c;
71
+ const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
72
+ const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
73
+ const t1 = h + sigma1 + ch + K[i] + W[i];
74
+ const t2 = sigma0 + maj;
75
+ h = g;
76
+ g = f;
77
+ f = e;
78
+ e = d + t1 | 0;
79
+ d = c;
80
+ c = b;
81
+ b = a;
82
+ a = t1 + t2 | 0;
83
+ }
84
+ this._hash.words[0] = this._hash.words[0] + a | 0;
85
+ this._hash.words[1] = this._hash.words[1] + b | 0;
86
+ this._hash.words[2] = this._hash.words[2] + c | 0;
87
+ this._hash.words[3] = this._hash.words[3] + d | 0;
88
+ this._hash.words[4] = this._hash.words[4] + e | 0;
89
+ this._hash.words[5] = this._hash.words[5] + f | 0;
90
+ this._hash.words[6] = this._hash.words[6] + g | 0;
91
+ this._hash.words[7] = this._hash.words[7] + h | 0;
92
+ }
93
+ }
94
+ export {
95
+ SHA256
96
+ };
@@ -0,0 +1,9 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ export declare class SHA512 extends Hasher {
4
+ private _hash;
5
+ constructor();
6
+ reset(): void;
7
+ protected _doFinalize(): WordArray;
8
+ protected _doProcessBlock(m: number[], offset: number): void;
9
+ }
@@ -0,0 +1,221 @@
1
+ import { Hasher } from "../lib/hasher.class.js";
2
+ import { X64Word } from "../lib/x64-word.class.js";
3
+ import { X64WordArray } from "../lib/x64-word-array.class.js";
4
+ const K = [
5
+ new X64Word(1116352408, 3609767458),
6
+ new X64Word(1899447441, 602891725),
7
+ new X64Word(3049323471, 3964484399),
8
+ new X64Word(3921009573, 2173295548),
9
+ new X64Word(961987163, 4081628472),
10
+ new X64Word(1508970993, 3053834265),
11
+ new X64Word(2453635748, 2937671579),
12
+ new X64Word(2870763221, 3664609560),
13
+ new X64Word(3624381080, 2734883394),
14
+ new X64Word(310598401, 1164996542),
15
+ new X64Word(607225278, 1323610764),
16
+ new X64Word(1426881987, 3590304994),
17
+ new X64Word(1925078388, 4068182383),
18
+ new X64Word(2162078206, 991336113),
19
+ new X64Word(2614888103, 633803317),
20
+ new X64Word(3248222580, 3479774868),
21
+ new X64Word(3835390401, 2666613458),
22
+ new X64Word(4022224774, 944711139),
23
+ new X64Word(264347078, 2341262773),
24
+ new X64Word(604807628, 2007800933),
25
+ new X64Word(770255983, 1495990901),
26
+ new X64Word(1249150122, 1856431235),
27
+ new X64Word(1555081692, 3175218132),
28
+ new X64Word(1996064986, 2198950837),
29
+ new X64Word(2554220882, 3999719339),
30
+ new X64Word(2821834349, 766784016),
31
+ new X64Word(2952996808, 2566594879),
32
+ new X64Word(3210313671, 3203337956),
33
+ new X64Word(3336571891, 1034457026),
34
+ new X64Word(3584528711, 2466948901),
35
+ new X64Word(113926993, 3758326383),
36
+ new X64Word(338241895, 168717936),
37
+ new X64Word(666307205, 1188179964),
38
+ new X64Word(773529912, 1546045734),
39
+ new X64Word(1294757372, 1522805485),
40
+ new X64Word(1396182291, 2643833823),
41
+ new X64Word(1695183700, 2343527390),
42
+ new X64Word(1986661051, 1014477480),
43
+ new X64Word(2177026350, 1206759142),
44
+ new X64Word(2456956037, 344077627),
45
+ new X64Word(2730485921, 1290863460),
46
+ new X64Word(2820302411, 3158454273),
47
+ new X64Word(3259730800, 3505952657),
48
+ new X64Word(3345764771, 106217008),
49
+ new X64Word(3516065817, 3606008344),
50
+ new X64Word(3600352804, 1432725776),
51
+ new X64Word(4094571909, 1467031594),
52
+ new X64Word(275423344, 851169720),
53
+ new X64Word(430227734, 3100823752),
54
+ new X64Word(506948616, 1363258195),
55
+ new X64Word(659060556, 3750685593),
56
+ new X64Word(883997877, 3785050280),
57
+ new X64Word(958139571, 3318307427),
58
+ new X64Word(1322822218, 3812723403),
59
+ new X64Word(1537002063, 2003034995),
60
+ new X64Word(1747873779, 3602036899),
61
+ new X64Word(1955562222, 1575990012),
62
+ new X64Word(2024104815, 1125592928),
63
+ new X64Word(2227730452, 2716904306),
64
+ new X64Word(2361852424, 442776044),
65
+ new X64Word(2428436474, 593698344),
66
+ new X64Word(2756734187, 3733110249),
67
+ new X64Word(3204031479, 2999351573),
68
+ new X64Word(3329325298, 3815920427),
69
+ new X64Word(3391569614, 3928383900),
70
+ new X64Word(3515267271, 566280711),
71
+ new X64Word(3940187606, 3454069534),
72
+ new X64Word(4118630271, 4000239992),
73
+ new X64Word(116418474, 1914138554),
74
+ new X64Word(174292421, 2731055270),
75
+ new X64Word(289380356, 3203993006),
76
+ new X64Word(460393269, 320620315),
77
+ new X64Word(685471733, 587496836),
78
+ new X64Word(852142971, 1086792851),
79
+ new X64Word(1017036298, 365543100),
80
+ new X64Word(1126000580, 2618297676),
81
+ new X64Word(1288033470, 3409855158),
82
+ new X64Word(1501505948, 4234509866),
83
+ new X64Word(1607167915, 987167468),
84
+ new X64Word(1816402316, 1246189591)
85
+ ];
86
+ const W = [];
87
+ (function() {
88
+ for (let i = 0; i < 80; i++) {
89
+ W[i] = new X64Word(void 0, void 0);
90
+ }
91
+ })();
92
+ class SHA512 extends Hasher {
93
+ constructor() {
94
+ super({
95
+ blockSize: 1024 / 32
96
+ });
97
+ }
98
+ reset() {
99
+ super.reset();
100
+ this._hash = new X64WordArray([
101
+ new X64Word(1779033703, 4089235720),
102
+ new X64Word(3144134277, 2227873595),
103
+ new X64Word(1013904242, 4271175723),
104
+ new X64Word(2773480762, 1595750129),
105
+ new X64Word(1359893119, 2917565137),
106
+ new X64Word(2600822924, 725511199),
107
+ new X64Word(528734635, 4215389547),
108
+ new X64Word(1541459225, 327033209)
109
+ ]);
110
+ }
111
+ _doFinalize() {
112
+ const data = this._data;
113
+ const dataWords = data.words;
114
+ const nBitsTotal = this._nDataBytes * 8;
115
+ const nBitsLeft = data.sigBytes * 8;
116
+ dataWords[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
117
+ dataWords[(nBitsLeft + 128 >>> 10 << 5) + 30] = Math.floor(nBitsTotal / 4294967296);
118
+ dataWords[(nBitsLeft + 128 >>> 10 << 5) + 31] = nBitsTotal;
119
+ data.sigBytes = dataWords.length * 4;
120
+ this._process();
121
+ return this._hash.toX32();
122
+ }
123
+ _doProcessBlock(m, offset) {
124
+ let ah = this._hash.words[0].high;
125
+ let al = this._hash.words[0].low;
126
+ let bh = this._hash.words[1].high;
127
+ let bl = this._hash.words[1].low;
128
+ let ch = this._hash.words[2].high;
129
+ let cl = this._hash.words[2].low;
130
+ let dh = this._hash.words[3].high;
131
+ let dl = this._hash.words[3].low;
132
+ let eh = this._hash.words[4].high;
133
+ let el = this._hash.words[4].low;
134
+ let fh = this._hash.words[5].high;
135
+ let fl = this._hash.words[5].low;
136
+ let gh = this._hash.words[6].high;
137
+ let gl = this._hash.words[6].low;
138
+ let hh = this._hash.words[7].high;
139
+ let hl = this._hash.words[7].low;
140
+ for (let i = 0; i < 80; i++) {
141
+ let currentLow;
142
+ let currentHi;
143
+ if (i < 16) {
144
+ currentHi = W[i].high = m[offset + i * 2] | 0;
145
+ currentLow = W[i].low = m[offset + i * 2 + 1] | 0;
146
+ } else {
147
+ const gamma0x = W[i - 15];
148
+ const gamma0xh = gamma0x.high;
149
+ const gamma0xl = gamma0x.low;
150
+ const gamma0h = (gamma0xh >>> 1 | gamma0xl << 31) ^ (gamma0xh >>> 8 | gamma0xl << 24) ^ gamma0xh >>> 7;
151
+ const gamma0l = (gamma0xl >>> 1 | gamma0xh << 31) ^ (gamma0xl >>> 8 | gamma0xh << 24) ^ (gamma0xl >>> 7 | gamma0xh << 25);
152
+ const gamma1x = W[i - 2];
153
+ const gamma1xh = gamma1x.high;
154
+ const gamma1xl = gamma1x.low;
155
+ const gamma1h = (gamma1xh >>> 19 | gamma1xl << 13) ^ (gamma1xh << 3 | gamma1xl >>> 29) ^ gamma1xh >>> 6;
156
+ const gamma1l = (gamma1xl >>> 19 | gamma1xh << 13) ^ (gamma1xl << 3 | gamma1xh >>> 29) ^ (gamma1xl >>> 6 | gamma1xh << 26);
157
+ currentLow = gamma0l + W[i - 7].low;
158
+ currentHi = gamma0h + W[i - 7].high + (currentLow >>> 0 < gamma0l >>> 0 ? 1 : 0);
159
+ currentLow = currentLow + gamma1l;
160
+ currentHi = currentHi + gamma1h + (currentLow >>> 0 < gamma1l >>> 0 ? 1 : 0);
161
+ currentLow = currentLow + W[i - 16].low;
162
+ currentHi = currentHi + W[i - 16].high + (currentLow >>> 0 < W[i - 16].low >>> 0 ? 1 : 0);
163
+ W[i].high = currentHi;
164
+ W[i].low = currentLow;
165
+ }
166
+ const chh = eh & fh ^ ~eh & gh;
167
+ const chl = el & fl ^ ~el & gl;
168
+ const majh = ah & bh ^ ah & ch ^ bh & ch;
169
+ const majl = al & bl ^ al & cl ^ bl & cl;
170
+ const sigma0h = (ah >>> 28 | al << 4) ^ (ah << 30 | al >>> 2) ^ (ah << 25 | al >>> 7);
171
+ const sigma0l = (al >>> 28 | ah << 4) ^ (al << 30 | ah >>> 2) ^ (al << 25 | ah >>> 7);
172
+ const sigma1h = (eh >>> 14 | el << 18) ^ (eh >>> 18 | el << 14) ^ (eh << 23 | el >>> 9);
173
+ const sigma1l = (el >>> 14 | eh << 18) ^ (el >>> 18 | eh << 14) ^ (el << 23 | eh >>> 9);
174
+ let t1l = hl + sigma1l;
175
+ let t1h = hh + sigma1h + (t1l >>> 0 < hl >>> 0 ? 1 : 0);
176
+ t1l = t1l + chl;
177
+ t1h = t1h + chh + (t1l >>> 0 < chl >>> 0 ? 1 : 0);
178
+ t1l = t1l + K[i].low;
179
+ t1h = t1h + K[i].high + (t1l >>> 0 < K[i].low >>> 0 ? 1 : 0);
180
+ t1l = t1l + currentLow;
181
+ t1h = t1h + currentHi + (t1l >>> 0 < currentLow >>> 0 ? 1 : 0);
182
+ const t2l = sigma0l + majl;
183
+ const t2h = sigma0h + majh + (t2l >>> 0 < sigma0l >>> 0 ? 1 : 0);
184
+ hh = gh;
185
+ hl = gl;
186
+ gh = fh;
187
+ gl = fl;
188
+ fh = eh;
189
+ fl = el;
190
+ el = dl + t1l | 0;
191
+ eh = dh + t1h + (el >>> 0 < dl >>> 0 ? 1 : 0) | 0;
192
+ dh = ch;
193
+ dl = cl;
194
+ ch = bh;
195
+ cl = bl;
196
+ bh = ah;
197
+ bl = al;
198
+ al = t1l + t2l | 0;
199
+ ah = t1h + t2h + (al >>> 0 < t1l >>> 0 ? 1 : 0) | 0;
200
+ }
201
+ this._hash.words[0].low = this._hash.words[0].low = this._hash.words[0].low + al;
202
+ this._hash.words[0].high = this._hash.words[0].high + ah + (this._hash.words[0].low >>> 0 < al >>> 0 ? 1 : 0);
203
+ this._hash.words[1].low = this._hash.words[1].low = this._hash.words[1].low + bl;
204
+ this._hash.words[1].high = this._hash.words[1].high + bh + (this._hash.words[1].low >>> 0 < bl >>> 0 ? 1 : 0);
205
+ this._hash.words[2].low = this._hash.words[2].low = this._hash.words[2].low + cl;
206
+ this._hash.words[2].high = this._hash.words[2].high + ch + (this._hash.words[2].low >>> 0 < cl >>> 0 ? 1 : 0);
207
+ this._hash.words[3].low = this._hash.words[3].low = this._hash.words[3].low + dl;
208
+ this._hash.words[3].high = this._hash.words[3].high + dh + (this._hash.words[3].low >>> 0 < dl >>> 0 ? 1 : 0);
209
+ this._hash.words[4].low = this._hash.words[4].low = this._hash.words[4].low + el;
210
+ this._hash.words[4].high = this._hash.words[4].high + eh + (this._hash.words[4].low >>> 0 < el >>> 0 ? 1 : 0);
211
+ this._hash.words[5].low = this._hash.words[5].low = this._hash.words[5].low + fl;
212
+ this._hash.words[5].high = this._hash.words[5].high + fh + (this._hash.words[5].low >>> 0 < fl >>> 0 ? 1 : 0);
213
+ this._hash.words[6].low = this._hash.words[6].low = this._hash.words[6].low + gl;
214
+ this._hash.words[6].high = this._hash.words[6].high + gh + (this._hash.words[6].low >>> 0 < gl >>> 0 ? 1 : 0);
215
+ this._hash.words[7].low = this._hash.words[7].low = this._hash.words[7].low + hl;
216
+ this._hash.words[7].high = this._hash.words[7].high + hh + (this._hash.words[7].low >>> 0 < hl >>> 0 ? 1 : 0);
217
+ }
218
+ }
219
+ export {
220
+ SHA512
221
+ };
@@ -0,0 +1,16 @@
1
+ import { BlockCipher } from "../lib/block-cipher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ import { BufferedBlockAlgorithmConfig } from "../lib/buffered-block-algorithm-config.interface.js";
4
+ import { DES } from "./des.class.js";
5
+ export declare class TripleDES extends BlockCipher {
6
+ static blockSize: number;
7
+ static ivSize: number;
8
+ static keySize: number;
9
+ protected _des1: DES;
10
+ protected _des2: DES;
11
+ protected _des3: DES;
12
+ constructor(xformMode: number, key: WordArray, cfg?: BufferedBlockAlgorithmConfig);
13
+ decryptBlock(m: number[], offset: number): void;
14
+ encryptBlock(m: number[], offset: number): void;
15
+ reset(): void;
16
+ }
@@ -0,0 +1,37 @@
1
+ import { BlockCipher } from "../lib/block-cipher.class.js";
2
+ import { WordArray } from "../lib/word-array.class.js";
3
+ import { DES } from "./des.class.js";
4
+ class TripleDES extends BlockCipher {
5
+ constructor(xformMode, key, cfg) {
6
+ super(xformMode, key, cfg);
7
+ this.reset();
8
+ }
9
+ decryptBlock(m, offset) {
10
+ this._des3.decryptBlock(m, offset);
11
+ this._des2.encryptBlock(m, offset);
12
+ this._des1.decryptBlock(m, offset);
13
+ }
14
+ encryptBlock(m, offset) {
15
+ this._des1.encryptBlock(m, offset);
16
+ this._des2.decryptBlock(m, offset);
17
+ this._des3.encryptBlock(m, offset);
18
+ }
19
+ reset() {
20
+ super.reset();
21
+ if (this._key.words.length !== 2 && this._key.words.length !== 4 && this._key.words.length < 6) {
22
+ throw new Error("Invalid key length - 3DES requires the key length to be 64, 128, 192 or >192.");
23
+ }
24
+ const key1 = this._key.words.slice(0, 2);
25
+ const key2 = this._key.words.length < 4 ? this._key.words.slice(0, 2) : this._key.words.slice(2, 4);
26
+ const key3 = this._key.words.length < 6 ? this._key.words.slice(0, 2) : this._key.words.slice(4, 6);
27
+ this._des1 = DES.createEncryptor(new WordArray(key1));
28
+ this._des2 = DES.createEncryptor(new WordArray(key2));
29
+ this._des3 = DES.createEncryptor(new WordArray(key3));
30
+ }
31
+ }
32
+ TripleDES.blockSize = 192 / 32;
33
+ TripleDES.ivSize = 64 / 32;
34
+ TripleDES.keySize = 64 / 32;
35
+ export {
36
+ TripleDES
37
+ };
@@ -0,0 +1,31 @@
1
+ import { WordArray } from "../lib/word-array.class.js";
2
+ import { AbstractEncoder } from "./encoder.model.js";
3
+ export declare class Base64 implements AbstractEncoder {
4
+ protected static _map: string;
5
+ protected static _reverseMap: number[] | undefined;
6
+ /**
7
+ * Converts a Base64 string to a word array.
8
+ *
9
+ * @param base64Str The Base64 string.
10
+ *
11
+ * @return The word array.
12
+ *
13
+ * @example
14
+ *
15
+ * let wordArray = Base64.parse(base64String);
16
+ */
17
+ static parse(base64Str: string): WordArray;
18
+ static parseLoop(base64Str: string, base64StrLength: number, reverseMap: number[]): WordArray;
19
+ /**
20
+ * Converts a word array to a Base64 string.
21
+ *
22
+ * @param wordArray The word array.
23
+ *
24
+ * @return The Base64 string.
25
+ *
26
+ * @example
27
+ *
28
+ * let base64String = Base64.stringify(wordArray);
29
+ */
30
+ static stringify(wordArray: WordArray): string;
31
+ }