simple-crypto-utils 1.0.0 → 1.0.1

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 (219) hide show
  1. package/package.json +3 -27
  2. package/dist/crypto/decrypt.d.ts +0 -1
  3. package/dist/crypto/decrypt.d.ts.map +0 -1
  4. package/dist/crypto/decrypt.js +0 -2
  5. package/dist/crypto/decrypt.js.map +0 -1
  6. package/dist/crypto/encrypt.d.ts +0 -1
  7. package/dist/crypto/encrypt.d.ts.map +0 -1
  8. package/dist/crypto/encrypt.js +0 -2
  9. package/dist/crypto/encrypt.js.map +0 -1
  10. package/dist/crypto/signMessage.d.ts +0 -1
  11. package/dist/crypto/signMessage.d.ts.map +0 -1
  12. package/dist/crypto/signMessage.js +0 -2
  13. package/dist/crypto/signMessage.js.map +0 -1
  14. package/dist/crypto/verifyMessage.d.ts +0 -1
  15. package/dist/crypto/verifyMessage.d.ts.map +0 -1
  16. package/dist/crypto/verifyMessage.js +0 -2
  17. package/dist/crypto/verifyMessage.js.map +0 -1
  18. package/dist/crypto-asymmetricaly/file/decryptFile.d.ts +0 -2
  19. package/dist/crypto-asymmetricaly/file/decryptFile.d.ts.map +0 -1
  20. package/dist/crypto-asymmetricaly/file/decryptFile.js +0 -93
  21. package/dist/crypto-asymmetricaly/file/decryptFile.js.map +0 -1
  22. package/dist/crypto-asymmetricaly/file/encryptFile.d.ts +0 -3
  23. package/dist/crypto-asymmetricaly/file/encryptFile.d.ts.map +0 -1
  24. package/dist/crypto-asymmetricaly/file/encryptFile.js +0 -110
  25. package/dist/crypto-asymmetricaly/file/encryptFile.js.map +0 -1
  26. package/dist/crypto-asymmetricaly/index.d.ts +0 -5
  27. package/dist/crypto-asymmetricaly/index.d.ts.map +0 -1
  28. package/dist/crypto-asymmetricaly/index.js +0 -5
  29. package/dist/crypto-asymmetricaly/index.js.map +0 -1
  30. package/dist/crypto-asymmetricaly/keys/generateRSA.d.ts +0 -5
  31. package/dist/crypto-asymmetricaly/keys/generateRSA.d.ts.map +0 -1
  32. package/dist/crypto-asymmetricaly/keys/generateRSA.js +0 -24
  33. package/dist/crypto-asymmetricaly/keys/generateRSA.js.map +0 -1
  34. package/dist/crypto-asymmetricaly/rsa/unwrapKey.d.ts +0 -1
  35. package/dist/crypto-asymmetricaly/rsa/unwrapKey.d.ts.map +0 -1
  36. package/dist/crypto-asymmetricaly/rsa/unwrapKey.js +0 -2
  37. package/dist/crypto-asymmetricaly/rsa/unwrapKey.js.map +0 -1
  38. package/dist/crypto-asymmetricaly/rsa/wrapKey.d.ts +0 -1
  39. package/dist/crypto-asymmetricaly/rsa/wrapKey.d.ts.map +0 -1
  40. package/dist/crypto-asymmetricaly/rsa/wrapKey.js +0 -2
  41. package/dist/crypto-asymmetricaly/rsa/wrapKey.js.map +0 -1
  42. package/dist/crypto-asymmetricaly/string/decryptString.d.ts +0 -2
  43. package/dist/crypto-asymmetricaly/string/decryptString.d.ts.map +0 -1
  44. package/dist/crypto-asymmetricaly/string/decryptString.js +0 -47
  45. package/dist/crypto-asymmetricaly/string/decryptString.js.map +0 -1
  46. package/dist/crypto-asymmetricaly/string/encryptString.d.ts +0 -7
  47. package/dist/crypto-asymmetricaly/string/encryptString.d.ts.map +0 -1
  48. package/dist/crypto-asymmetricaly/string/encryptString.js +0 -26
  49. package/dist/crypto-asymmetricaly/string/encryptString.js.map +0 -1
  50. package/dist/crypto-asymmetricaly/string/generateAES.d.ts +0 -5
  51. package/dist/crypto-asymmetricaly/string/generateAES.d.ts.map +0 -1
  52. package/dist/crypto-asymmetricaly/string/generateAES.js +0 -7
  53. package/dist/crypto-asymmetricaly/string/generateAES.js.map +0 -1
  54. package/dist/crypto-symmetricaly/decrypt.d.ts +0 -2
  55. package/dist/crypto-symmetricaly/decrypt.d.ts.map +0 -1
  56. package/dist/crypto-symmetricaly/decrypt.js +0 -14
  57. package/dist/crypto-symmetricaly/decrypt.js.map +0 -1
  58. package/dist/crypto-symmetricaly/encrypt.d.ts +0 -2
  59. package/dist/crypto-symmetricaly/encrypt.d.ts.map +0 -1
  60. package/dist/crypto-symmetricaly/encrypt.js +0 -16
  61. package/dist/crypto-symmetricaly/encrypt.js.map +0 -1
  62. package/dist/crypto-symmetricaly/index.d.ts +0 -3
  63. package/dist/crypto-symmetricaly/index.d.ts.map +0 -1
  64. package/dist/crypto-symmetricaly/index.js +0 -3
  65. package/dist/crypto-symmetricaly/index.js.map +0 -1
  66. package/dist/crypto-symmetricaly/signMessage.d.ts +0 -1
  67. package/dist/crypto-symmetricaly/signMessage.d.ts.map +0 -1
  68. package/dist/crypto-symmetricaly/signMessage.js +0 -2
  69. package/dist/crypto-symmetricaly/signMessage.js.map +0 -1
  70. package/dist/crypto-symmetricaly/verifyMessage.d.ts +0 -1
  71. package/dist/crypto-symmetricaly/verifyMessage.d.ts.map +0 -1
  72. package/dist/crypto-symmetricaly/verifyMessage.js +0 -2
  73. package/dist/crypto-symmetricaly/verifyMessage.js.map +0 -1
  74. package/dist/hash/hash.d.ts +0 -2
  75. package/dist/hash/hash.d.ts.map +0 -1
  76. package/dist/hash/hash.js +0 -7
  77. package/dist/hash/hash.js.map +0 -1
  78. package/dist/hash/hashHmac.d.ts +0 -2
  79. package/dist/hash/hashHmac.d.ts.map +0 -1
  80. package/dist/hash/hashHmac.js +0 -5
  81. package/dist/hash/hashHmac.js.map +0 -1
  82. package/dist/hash/index.d.ts +0 -4
  83. package/dist/hash/index.d.ts.map +0 -1
  84. package/dist/hash/index.js +0 -4
  85. package/dist/hash/index.js.map +0 -1
  86. package/dist/hash/verifyHmac.d.ts +0 -2
  87. package/dist/hash/verifyHmac.d.ts.map +0 -1
  88. package/dist/hash/verifyHmac.js +0 -10
  89. package/dist/hash/verifyHmac.js.map +0 -1
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/index.js.map +0 -1
  92. package/dist/otp/TOTP.d.ts +0 -10
  93. package/dist/otp/TOTP.d.ts.map +0 -1
  94. package/dist/otp/TOTP.js +0 -33
  95. package/dist/otp/TOTP.js.map +0 -1
  96. package/dist/otp/generate.d.ts +0 -2
  97. package/dist/otp/generate.d.ts.map +0 -1
  98. package/dist/otp/generate.js +0 -7
  99. package/dist/otp/generate.js.map +0 -1
  100. package/dist/otp/generateOTP.d.ts +0 -1
  101. package/dist/otp/generateOTP.d.ts.map +0 -1
  102. package/dist/otp/generateOTP.js +0 -2
  103. package/dist/otp/generateOTP.js.map +0 -1
  104. package/dist/otp/hash.d.ts +0 -2
  105. package/dist/otp/hash.d.ts.map +0 -1
  106. package/dist/otp/hash.js +0 -5
  107. package/dist/otp/hash.js.map +0 -1
  108. package/dist/otp/index.d.ts +0 -3
  109. package/dist/otp/index.d.ts.map +0 -1
  110. package/dist/otp/index.js +0 -3
  111. package/dist/otp/index.js.map +0 -1
  112. package/dist/otp/verifyOTP.d.ts +0 -1
  113. package/dist/otp/verifyOTP.d.ts.map +0 -1
  114. package/dist/otp/verifyOTP.js +0 -2
  115. package/dist/otp/verifyOTP.js.map +0 -1
  116. package/dist/password/generate.d.ts +0 -15
  117. package/dist/password/generate.d.ts.map +0 -1
  118. package/dist/password/generate.js +0 -44
  119. package/dist/password/generate.js.map +0 -1
  120. package/dist/password/generatePassword.d.ts +0 -2
  121. package/dist/password/generatePassword.d.ts.map +0 -1
  122. package/dist/password/generatePassword.js +0 -10
  123. package/dist/password/generatePassword.js.map +0 -1
  124. package/dist/password/hash.d.ts +0 -2
  125. package/dist/password/hash.d.ts.map +0 -1
  126. package/dist/password/hash.js +0 -12
  127. package/dist/password/hash.js.map +0 -1
  128. package/dist/password/hashPassword.d.ts +0 -1
  129. package/dist/password/hashPassword.d.ts.map +0 -1
  130. package/dist/password/hashPassword.js +0 -2
  131. package/dist/password/hashPassword.js.map +0 -1
  132. package/dist/password/index.d.ts +0 -4
  133. package/dist/password/index.d.ts.map +0 -1
  134. package/dist/password/index.js +0 -4
  135. package/dist/password/index.js.map +0 -1
  136. package/dist/password/validatePassword.d.ts +0 -1
  137. package/dist/password/validatePassword.d.ts.map +0 -1
  138. package/dist/password/validatePassword.js +0 -2
  139. package/dist/password/validatePassword.js.map +0 -1
  140. package/dist/password/verify.d.ts +0 -2
  141. package/dist/password/verify.d.ts.map +0 -1
  142. package/dist/password/verify.js +0 -33
  143. package/dist/password/verify.js.map +0 -1
  144. package/dist/password/verifyPassword.d.ts +0 -1
  145. package/dist/password/verifyPassword.d.ts.map +0 -1
  146. package/dist/password/verifyPassword.js +0 -2
  147. package/dist/password/verifyPassword.js.map +0 -1
  148. package/dist/signature/index.d.ts +0 -46
  149. package/dist/signature/index.d.ts.map +0 -1
  150. package/dist/signature/index.js +0 -51
  151. package/dist/signature/index.js.map +0 -1
  152. package/dist/signature/serialize.d.ts +0 -4
  153. package/dist/signature/serialize.d.ts.map +0 -1
  154. package/dist/signature/serialize.js +0 -33
  155. package/dist/signature/serialize.js.map +0 -1
  156. package/dist/signature/sign.d.ts +0 -3
  157. package/dist/signature/sign.d.ts.map +0 -1
  158. package/dist/signature/sign.js +0 -26
  159. package/dist/signature/sign.js.map +0 -1
  160. package/dist/signature/types.d.ts +0 -16
  161. package/dist/signature/types.d.ts.map +0 -1
  162. package/dist/signature/types.js +0 -2
  163. package/dist/signature/types.js.map +0 -1
  164. package/dist/signature/verify.d.ts +0 -3
  165. package/dist/signature/verify.d.ts.map +0 -1
  166. package/dist/signature/verify.js +0 -26
  167. package/dist/signature/verify.js.map +0 -1
  168. package/dist/test-minimal.d.ts +0 -1
  169. package/dist/test-minimal.d.ts.map +0 -1
  170. package/dist/test-minimal.js +0 -4
  171. package/dist/test-minimal.js.map +0 -1
  172. package/dist/test.d.ts +0 -2
  173. package/dist/test.d.ts.map +0 -1
  174. package/dist/test.js +0 -33
  175. package/dist/test.js.map +0 -1
  176. package/dist/token/generateRandomToken.d.ts +0 -1
  177. package/dist/token/generateRandomToken.d.ts.map +0 -1
  178. package/dist/token/generateRandomToken.js +0 -2
  179. package/dist/token/generateRandomToken.js.map +0 -1
  180. package/dist/token/generateUUID.d.ts +0 -1
  181. package/dist/token/generateUUID.d.ts.map +0 -1
  182. package/dist/token/generateUUID.js +0 -2
  183. package/dist/token/generateUUID.js.map +0 -1
  184. package/dist/token/hashToken.d.ts +0 -1
  185. package/dist/token/hashToken.d.ts.map +0 -1
  186. package/dist/token/hashToken.js +0 -2
  187. package/dist/token/hashToken.js.map +0 -1
  188. package/dist/utlis/constants.d.ts +0 -4
  189. package/dist/utlis/constants.d.ts.map +0 -1
  190. package/dist/utlis/constants.js +0 -4
  191. package/dist/utlis/constants.js.map +0 -1
  192. package/dist/utlis/entropyScore.d.ts +0 -1
  193. package/dist/utlis/entropyScore.d.ts.map +0 -1
  194. package/dist/utlis/entropyScore.js +0 -2
  195. package/dist/utlis/entropyScore.js.map +0 -1
  196. package/dist/utlis/generateRandomBytes.d.ts +0 -2
  197. package/dist/utlis/generateRandomBytes.d.ts.map +0 -1
  198. package/dist/utlis/generateRandomBytes.js +0 -9
  199. package/dist/utlis/generateRandomBytes.js.map +0 -1
  200. package/dist/utlis/maskSensitive.d.ts +0 -1
  201. package/dist/utlis/maskSensitive.d.ts.map +0 -1
  202. package/dist/utlis/maskSensitive.js +0 -2
  203. package/dist/utlis/maskSensitive.js.map +0 -1
  204. package/dist/utlis/safeCompare.d.ts +0 -1
  205. package/dist/utlis/safeCompare.d.ts.map +0 -1
  206. package/dist/utlis/safeCompare.js +0 -2
  207. package/dist/utlis/safeCompare.js.map +0 -1
  208. package/dist/uuid/generate.d.ts +0 -2
  209. package/dist/uuid/generate.d.ts.map +0 -1
  210. package/dist/uuid/generate.js +0 -5
  211. package/dist/uuid/generate.js.map +0 -1
  212. package/dist/uuid/hashToken.d.ts +0 -1
  213. package/dist/uuid/hashToken.d.ts.map +0 -1
  214. package/dist/uuid/hashToken.js +0 -6
  215. package/dist/uuid/hashToken.js.map +0 -1
  216. package/dist/uuid/index.d.ts +0 -2
  217. package/dist/uuid/index.d.ts.map +0 -1
  218. package/dist/uuid/index.js +0 -2
  219. package/dist/uuid/index.js.map +0 -1
package/package.json CHANGED
@@ -1,37 +1,13 @@
1
1
  {
2
2
  "name": "simple-crypto-utils",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A TypeScript cryptography utility library for educational purposes only. Not intended for production use.",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {
8
8
  "types": "./dist/index.d.ts",
9
- "import": "./dist/index.mjs",
9
+ "import": "./dist/index.js",
10
10
  "require": "./dist/index.cjs"
11
- },
12
- "./crypto": {
13
- "import": "./dist/crypto/index.mjs",
14
- "require": "./dist/crypto/index.cjs"
15
- },
16
- "./hash": {
17
- "import": "./dist/hash/index.mjs",
18
- "require": "./dist/hash/index.cjs"
19
- },
20
- "./otp": {
21
- "import": "./dist/otp/index.mjs",
22
- "require": "./dist/otp/index.cjs"
23
- },
24
- "./password": {
25
- "import": "./dist/password/index.mjs",
26
- "require": "./dist/password/index.cjs"
27
- },
28
- "./signature": {
29
- "import": "./dist/signature/index.mjs",
30
- "require": "./dist/signature/index.cjs"
31
- },
32
- "./uuid": {
33
- "import": "./dist/signature/index.mjs",
34
- "require": "./dist/signature/index.cjs"
35
11
  }
36
12
  },
37
13
  "types": "./dist/index.d.ts",
@@ -40,7 +16,7 @@
40
16
  ],
41
17
  "scripts": {
42
18
  "clean": "rm -rf dist",
43
- "build": "tsup src/index.ts --format cjs,esm --dts",
19
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
44
20
  "test": "echo \"No tests yet\" && exit 0"
45
21
  },
46
22
  "keywords": [
@@ -1 +0,0 @@
1
- //# sourceMappingURL=decrypt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../src/crypto/decrypt.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=decrypt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../src/crypto/decrypt.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=encrypt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/crypto/encrypt.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=encrypt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encrypt.js","sourceRoot":"","sources":["../../src/crypto/encrypt.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=signMessage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signMessage.d.ts","sourceRoot":"","sources":["../../src/crypto/signMessage.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=signMessage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"signMessage.js","sourceRoot":"","sources":["../../src/crypto/signMessage.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=verifyMessage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verifyMessage.d.ts","sourceRoot":"","sources":["../../src/crypto/verifyMessage.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=verifyMessage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verifyMessage.js","sourceRoot":"","sources":["../../src/crypto/verifyMessage.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare function decryptFile(inputPath: string, outputPath: string, privateKey: string): Promise<void>;
2
- //# sourceMappingURL=decryptFile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptFile.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/file/decryptFile.ts"],"names":[],"mappings":"AAWA,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,iBA4HnB"}
@@ -1,93 +0,0 @@
1
- import { createReadStream, createWriteStream } from "fs";
2
- import { createDecipheriv, privateDecrypt, constants } from "crypto";
3
- import { pipeline } from "stream/promises";
4
- import { open } from "fs/promises";
5
- export async function decryptFile(inputPath, outputPath, privateKey) {
6
- // 1️⃣ Open file handle (doesn't load into memory)
7
- const fileHandle = await open(inputPath, "r");
8
- try {
9
- // 2️⃣ Read only the first 4 bytes to get header length
10
- const headerLengthBuf = Buffer.alloc(4);
11
- const { bytesRead: lengthBytesRead } = await fileHandle.read(headerLengthBuf, 0, 4, 0);
12
- if (lengthBytesRead < 4) {
13
- throw new Error(`File is too small (${lengthBytesRead} bytes). Expected at least 4 bytes for header length.`);
14
- }
15
- const headerLength = headerLengthBuf.readUInt32BE(0);
16
- console.log("Header length:", headerLength);
17
- // 3️⃣ Validate header length is reasonable
18
- if (headerLength > 10000) {
19
- throw new Error(`Header length suspiciously large (${headerLength} bytes). File may be corrupted.`);
20
- }
21
- // 4️⃣ Read only the header (not the entire file!)
22
- const headerBuf = Buffer.alloc(headerLength);
23
- const { bytesRead: headerBytesRead } = await fileHandle.read(headerBuf, 0, headerLength, 4);
24
- if (headerBytesRead < headerLength) {
25
- throw new Error(`File is too short to contain the header. Expected ${headerLength} bytes, got ${headerBytesRead}`);
26
- }
27
- // 5️⃣ Parse header JSON
28
- const headerJson = headerBuf.toString("utf8");
29
- console.log("Header JSON:", headerJson);
30
- let header;
31
- try {
32
- header = JSON.parse(headerJson);
33
- }
34
- catch (e) {
35
- throw new Error(`Failed to parse header JSON: ${e}`);
36
- }
37
- // 6️⃣ Validate header fields
38
- if (!header.encryptedKey || !header.iv || !header.authTag) {
39
- throw new Error("Invalid header: missing required fields");
40
- }
41
- // 7️⃣ Extract buffers from base64
42
- const encryptedKeyBuf = Buffer.from(header.encryptedKey, "base64");
43
- const iv = Buffer.from(header.iv, "base64");
44
- const authTag = Buffer.from(header.authTag, "base64");
45
- console.log("Encrypted key length:", encryptedKeyBuf.length);
46
- console.log("IV length:", iv.length);
47
- console.log("Auth tag length:", authTag.length);
48
- // 8️⃣ Validate buffer sizes
49
- if (iv.length !== 12) {
50
- throw new Error(`Invalid IV length: expected 12 bytes, got ${iv.length}`);
51
- }
52
- if (authTag.length !== 16) {
53
- throw new Error(`Invalid auth tag length: expected 16 bytes, got ${authTag.length}`);
54
- }
55
- // 9️⃣ Decrypt AES key with RSA private key
56
- let aesKey;
57
- try {
58
- aesKey = privateDecrypt({
59
- key: privateKey,
60
- padding: constants.RSA_PKCS1_OAEP_PADDING,
61
- oaepHash: "sha256",
62
- }, encryptedKeyBuf);
63
- }
64
- catch (e) {
65
- throw new Error(`Failed to decrypt AES key: ${e}`);
66
- }
67
- // Validate AES key length
68
- if (aesKey.length !== 32) {
69
- throw new Error(`Invalid AES key length: expected 32 bytes, got ${aesKey.length}`);
70
- }
71
- // 🔟 Create decipher
72
- const decipher = createDecipheriv("aes-256-gcm", aesKey, iv);
73
- decipher.setAuthTag(authTag);
74
- // 1️⃣1️⃣ Stream encrypted content (after header) → decipher → output
75
- // This streams the data, never loading the full file into memory
76
- const inputStream = createReadStream(inputPath, {
77
- start: 4 + headerLength,
78
- });
79
- const outputStream = createWriteStream(outputPath);
80
- try {
81
- await pipeline(inputStream, decipher, outputStream);
82
- console.log("✅ File decrypted successfully");
83
- }
84
- catch (e) {
85
- throw new Error(`Decryption failed (authentication error): ${e}`);
86
- }
87
- }
88
- finally {
89
- // Always close the file handle
90
- await fileHandle.close();
91
- }
92
- }
93
- //# sourceMappingURL=decryptFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptFile.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/file/decryptFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBA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C"}
@@ -1,3 +0,0 @@
1
- export declare function encryptFile(inputPath: string, outputPath: string, publicKey: string): Promise<void>;
2
- export declare function encryptFileSmall(inputPath: string, outputPath: string, publicKey: string): Promise<void>;
3
- //# sourceMappingURL=encryptFile.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptFile.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/file/encryptFile.ts"],"names":[],"mappings":"AAoBA,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,iBAelB;AAoED,wBAAsB,gBAAgB,CACpC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,iBAyDlB"}
@@ -1,110 +0,0 @@
1
- import { createReadStream, createWriteStream, readFileSync, writeFileSync, statSync, } from "fs";
2
- import { createCipheriv, publicEncrypt, randomBytes, constants } from "crypto";
3
- import { pipeline } from "stream/promises";
4
- import { tmpdir } from "os";
5
- import { join } from "path";
6
- // Memory-efficient version for large files
7
- export async function encryptFile(inputPath, outputPath, publicKey) {
8
- const LARGE_FILE_THRESHOLD = 100 * 1024 * 1024; // 100 MB
9
- const fileSize = statSync(inputPath).size;
10
- if (fileSize > LARGE_FILE_THRESHOLD) {
11
- console.log(`Large file detected (${(fileSize / 1024 / 1024).toFixed(2)} MB), using streaming...`);
12
- return encryptFileStreaming(inputPath, outputPath, publicKey);
13
- }
14
- else {
15
- return encryptFileSmall(inputPath, outputPath, publicKey);
16
- }
17
- }
18
- // Streaming version - never loads full file into memory
19
- async function encryptFileStreaming(inputPath, outputPath, publicKey) {
20
- // 1️⃣ Generate AES key + IV
21
- const aesKey = randomBytes(32);
22
- const iv = randomBytes(12);
23
- // 2️⃣ Encrypt AES key with RSA
24
- const encryptedKeyBuf = publicEncrypt({
25
- key: publicKey,
26
- padding: constants.RSA_PKCS1_OAEP_PADDING,
27
- oaepHash: "sha256",
28
- }, aesKey);
29
- // 3️⃣ Encrypt to temporary file
30
- const tempPath = join(tmpdir(), `temp-encrypt-${Date.now()}.tmp`);
31
- const tempStream = createWriteStream(tempPath);
32
- const cipher = createCipheriv("aes-256-gcm", aesKey, iv);
33
- const inputStream = createReadStream(inputPath);
34
- await pipeline(inputStream, cipher, tempStream);
35
- // 4️⃣ Get authTag
36
- const authTag = cipher.getAuthTag();
37
- // 5️⃣ Create header
38
- const header = {
39
- encryptedKey: encryptedKeyBuf.toString("base64"),
40
- iv: iv.toString("base64"),
41
- authTag: authTag.toString("base64"),
42
- };
43
- const headerJson = Buffer.from(JSON.stringify(header), "utf8");
44
- const headerLengthBuf = Buffer.alloc(4);
45
- headerLengthBuf.writeUInt32BE(headerJson.length, 0);
46
- // 6️⃣ Stream temp file to final output (memory-efficient)
47
- const outputStream = createWriteStream(outputPath);
48
- // Write header first
49
- outputStream.write(headerLengthBuf);
50
- outputStream.write(headerJson);
51
- // Stream encrypted data
52
- const tempReadStream = createReadStream(tempPath);
53
- await pipeline(tempReadStream, outputStream);
54
- // 7️⃣ Clean up temp file
55
- try {
56
- const { unlinkSync } = await import("fs");
57
- unlinkSync(tempPath);
58
- }
59
- catch (e) {
60
- console.warn("Could not delete temp file:", tempPath);
61
- }
62
- console.log("✅ File encrypted successfully (streaming mode)");
63
- console.log("Header length:", headerJson.length);
64
- }
65
- // Original version - good for files < 100 MB
66
- export async function encryptFileSmall(inputPath, outputPath, publicKey) {
67
- // 1️⃣ Generate AES key + IV
68
- const aesKey = randomBytes(32);
69
- const iv = randomBytes(12);
70
- // 2️⃣ Encrypt AES key with RSA
71
- const encryptedKeyBuf = publicEncrypt({
72
- key: publicKey,
73
- padding: constants.RSA_PKCS1_OAEP_PADDING,
74
- oaepHash: "sha256",
75
- }, aesKey);
76
- // 3️⃣ Encrypt to temporary file first to get authTag
77
- const tempPath = join(tmpdir(), `temp-encrypt-${Date.now()}.tmp`);
78
- const tempStream = createWriteStream(tempPath);
79
- const cipher = createCipheriv("aes-256-gcm", aesKey, iv);
80
- const inputStream = createReadStream(inputPath);
81
- await pipeline(inputStream, cipher, tempStream);
82
- // 4️⃣ Get authTag after encryption is complete
83
- const authTag = cipher.getAuthTag();
84
- // 5️⃣ Now create the final header with the real authTag
85
- const header = {
86
- encryptedKey: encryptedKeyBuf.toString("base64"),
87
- iv: iv.toString("base64"),
88
- authTag: authTag.toString("base64"),
89
- };
90
- const headerJson = Buffer.from(JSON.stringify(header), "utf8");
91
- const headerLengthBuf = Buffer.alloc(4);
92
- headerLengthBuf.writeUInt32BE(headerJson.length, 0);
93
- // 6️⃣ Read the encrypted data from temp file
94
- const encryptedData = readFileSync(tempPath);
95
- // 7️⃣ Write final file: header length + header + encrypted data
96
- const finalData = Buffer.concat([headerLengthBuf, headerJson, encryptedData]);
97
- writeFileSync(outputPath, finalData);
98
- // 8️⃣ Clean up temp file
99
- try {
100
- const { unlinkSync } = await import("fs");
101
- unlinkSync(tempPath);
102
- }
103
- catch (e) {
104
- console.warn("Could not delete temp file:", tempPath);
105
- }
106
- console.log("✅ File encrypted successfully");
107
- console.log("Header length:", headerJson.length);
108
- console.log("Auth tag:", authTag.toString("base64"));
109
- }
110
- //# sourceMappingURL=encryptFile.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptFile.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/file/encryptFile.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAS5B,2CAA2C;AAC3C,MAAM,CAAC,KA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AAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IAC/D,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxC,eAAe,CAAC,aAAa,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAEpD,6CAA6C;IAC7C,MAAM,aAAa,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE7C,gEAAgE;IAChE,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;IAC9E,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAErC,yBAAyB;IACzB,IAAI,CAAC;QACH,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QAC1C,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvD,CAAC"}
@@ -1,5 +0,0 @@
1
- export { generateRSAKeyPair } from "./keys/generateRSA";
2
- export { generateAESKey } from "./string/generateAES";
3
- export { encryptString } from "./string/encryptString";
4
- export { decryptString } from "./string/decryptString";
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/crypto-asymmetricaly/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,5 +0,0 @@
1
- export { generateRSAKeyPair } from "./keys/generateRSA";
2
- export { generateAESKey } from "./string/generateAES";
3
- export { encryptString } from "./string/encryptString";
4
- export { decryptString } from "./string/decryptString";
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/crypto-asymmetricaly/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC"}
@@ -1,5 +0,0 @@
1
- export declare function generateRSAKeyPair(): Promise<{
2
- publicKey: string;
3
- privateKey: string;
4
- }>;
5
- //# sourceMappingURL=generateRSA.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateRSA.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/keys/generateRSA.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI,OAAO,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC,CAwBD"}
@@ -1,24 +0,0 @@
1
- import { generateKeyPair } from "crypto";
2
- export function generateRSAKeyPair() {
3
- return new Promise((resolve, reject) => {
4
- generateKeyPair("rsa", {
5
- modulusLength: 2048,
6
- publicKeyEncoding: {
7
- type: "spki",
8
- format: "pem",
9
- },
10
- privateKeyEncoding: {
11
- type: "pkcs8",
12
- format: "pem",
13
- },
14
- }, (err, publicKey, privateKey) => {
15
- if (err)
16
- return reject(err);
17
- resolve({
18
- publicKey,
19
- privateKey,
20
- });
21
- });
22
- });
23
- }
24
- //# sourceMappingURL=generateRSA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateRSA.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/keys/generateRSA.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAEzC,MAAM,UAAU,kBAAkB;IAIhC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,eAAe,CACb,KAAK,EACL;YACE,aAAa,EAAE,IAAI;YACnB,iBAAiB,EAAE;gBACjB,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,KAAK;aACd;YACD,kBAAkB,EAAE;gBAClB,IAAI,EAAE,OAAO;gBACb,MAAM,EAAE,KAAK;aACd;SACF,EACD,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;YAC7B,IAAI,GAAG;gBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5B,OAAO,CAAC;gBACN,SAAS;gBACT,UAAU;aACX,CAAC,CAAC;QACL,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=unwrapKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unwrapKey.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/rsa/unwrapKey.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=unwrapKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unwrapKey.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/rsa/unwrapKey.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=wrapKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrapKey.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/rsa/wrapKey.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=wrapKey.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"wrapKey.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/rsa/wrapKey.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export declare function decryptString(encryptedData: string, encryptedKey: string, iv: string, authTag: string, privateKey: string): string;
2
- //# sourceMappingURL=decryptString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptString.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/decryptString.ts"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAC3B,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAsDR"}
@@ -1,47 +0,0 @@
1
- // decryptString.ts
2
- import { Buffer } from "buffer";
3
- import { createDecipheriv, privateDecrypt, constants } from "crypto";
4
- export function decryptString(encryptedData, encryptedKey, iv, authTag, privateKey) {
5
- // Decode from base64
6
- const encryptedDataBuf = Buffer.from(encryptedData, "base64");
7
- const encryptedKeyBuf = Buffer.from(encryptedKey, "base64"); // ✅ FIXED: removed .substring(0, 12)
8
- const ivBuf = Buffer.from(iv, "base64");
9
- const authTagBuf = Buffer.from(authTag, "base64");
10
- // Validate buffer sizes
11
- if (ivBuf.length !== 12) {
12
- throw new Error(`Invalid IV length: expected 12 bytes, got ${ivBuf.length}`);
13
- }
14
- if (authTagBuf.length !== 16) {
15
- throw new Error(`Invalid auth tag length: expected 16 bytes, got ${authTagBuf.length}`);
16
- }
17
- // Decrypt the AES key using RSA private key
18
- let aesKey;
19
- try {
20
- aesKey = privateDecrypt({
21
- key: privateKey,
22
- padding: constants.RSA_PKCS1_OAEP_PADDING,
23
- oaepHash: "sha256",
24
- }, encryptedKeyBuf);
25
- }
26
- catch (e) {
27
- throw new Error(`Failed to decrypt AES key: ${e}`);
28
- }
29
- // Validate AES key length
30
- if (aesKey.length !== 32) {
31
- throw new Error(`Invalid AES key length: expected 32 bytes, got ${aesKey.length}`);
32
- }
33
- // Decrypt the data using AES-256-GCM
34
- const decipher = createDecipheriv("aes-256-gcm", aesKey, ivBuf);
35
- decipher.setAuthTag(authTagBuf);
36
- try {
37
- const decrypted = Buffer.concat([
38
- decipher.update(encryptedDataBuf),
39
- decipher.final(),
40
- ]);
41
- return decrypted.toString("utf8");
42
- }
43
- catch (e) {
44
- throw new Error(`Decryption failed (authentication error): ${e}`);
45
- }
46
- }
47
- //# sourceMappingURL=decryptString.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decryptString.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/decryptString.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAErE,MAAM,UAAU,aAAa,CAC3B,aAAqB,EACrB,YAAoB,EACpB,EAAU,EACV,OAAe,EACf,UAAkB;IAElB,qBAAqB;IACrB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IAC9D,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAC,qCAAqC;IAClG,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAElD,wBAAwB;IACxB,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,6CAA6C,KAAK,CAAC,MAAM,EAAE,CAC5D,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,mDAAmD,UAAU,CAAC,MAAM,EAAE,CACvE,CAAC;IACJ,CAAC;IAED,4CAA4C;IAC5C,IAAI,MAAc,CAAC;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,cAAc,CACrB;YACE,GAAG,EAAE,UAAU;YACf,OAAO,EAAE,SAAS,CAAC,sBAAsB;YACzC,QAAQ,EAAE,QAAQ;SACnB,EACD,eAAe,CAChB,CAAC;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,0BAA0B;IAC1B,IAAI,MAAM,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,kDAAkD,MAAM,CAAC,MAAM,EAAE,CAClE,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAChE,QAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAEhC,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;YAC9B,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC;YACjC,QAAQ,CAAC,KAAK,EAAE;SACjB,CAAC,CAAC;QACH,OAAO,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACpC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,EAAE,CAAC,CAAC;IACpE,CAAC;AACH,CAAC"}
@@ -1,7 +0,0 @@
1
- export declare function encryptString(data: string, publicKey: string): {
2
- encryptedData: string;
3
- encryptedKey: string;
4
- iv: string;
5
- authTag: string;
6
- };
7
- //# sourceMappingURL=encryptString.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptString.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/encryptString.ts"],"names":[],"mappings":"AAIA,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,GAChB;IACD,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB,CA2BA"}
@@ -1,26 +0,0 @@
1
- // encryptString.ts
2
- import { createCipheriv, publicEncrypt, constants } from "crypto";
3
- import { generateAESKey } from "./generateAES";
4
- export function encryptString(data, publicKey) {
5
- const { key, iv } = generateAESKey();
6
- // Encrypt the data with AES-256-GCM
7
- const cipher = createCipheriv("aes-256-gcm", key, iv);
8
- const encryptedBuffer = Buffer.concat([
9
- cipher.update(data, "utf8"),
10
- cipher.final(),
11
- ]);
12
- const authTag = cipher.getAuthTag();
13
- // Encrypt the AES key with RSA public key
14
- const encryptedKey = publicEncrypt({
15
- key: publicKey,
16
- padding: constants.RSA_PKCS1_OAEP_PADDING,
17
- oaepHash: "sha256",
18
- }, key);
19
- return {
20
- encryptedData: encryptedBuffer.toString("base64"),
21
- encryptedKey: encryptedKey.toString("base64"),
22
- iv: iv.toString("base64"),
23
- authTag: authTag.toString("base64"),
24
- };
25
- }
26
- //# sourceMappingURL=encryptString.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encryptString.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/encryptString.ts"],"names":[],"mappings":"AAAA,mBAAmB;AACnB,OAAO,EAAe,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE/C,MAAM,UAAU,aAAa,CAC3B,IAAY,EACZ,SAAiB;IAOjB,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE,CAAC;IAErC,oCAAoC;IACpC,MAAM,MAAM,GAAG,cAAc,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtD,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;QACpC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC;QAC3B,MAAM,CAAC,KAAK,EAAE;KACf,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC;IAEpC,0CAA0C;IAC1C,MAAM,YAAY,GAAG,aAAa,CAChC;QACE,GAAG,EAAE,SAAS;QACd,OAAO,EAAE,SAAS,CAAC,sBAAsB;QACzC,QAAQ,EAAE,QAAQ;KACnB,EACD,GAAG,CACJ,CAAC;IAEF,OAAO;QACL,aAAa,EAAE,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACjD,YAAY,EAAE,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAC7C,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACzB,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;KACpC,CAAC;AACJ,CAAC"}
@@ -1,5 +0,0 @@
1
- export declare function generateAESKey(): {
2
- key: Buffer;
3
- iv: Buffer;
4
- };
5
- //# sourceMappingURL=generateAES.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateAES.d.ts","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/generateAES.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,IAAI;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAI5D"}
@@ -1,7 +0,0 @@
1
- import { randomBytes } from "crypto";
2
- export function generateAESKey() {
3
- const key = randomBytes(32);
4
- const iv = randomBytes(12);
5
- return { key, iv };
6
- }
7
- //# sourceMappingURL=generateAES.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateAES.js","sourceRoot":"","sources":["../../../src/crypto-asymmetricaly/string/generateAES.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,UAAU,cAAc;IAC5B,MAAM,GAAG,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC5B,MAAM,EAAE,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC3B,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;AACrB,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function decrypt(encHex: string, password: string): string;
2
- //# sourceMappingURL=decrypt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../src/crypto-symmetricaly/decrypt.ts"],"names":[],"mappings":"AAQA,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAcvD"}
@@ -1,14 +0,0 @@
1
- import { scryptSync, createDecipheriv, } from "crypto";
2
- // Decrypt
3
- export function decrypt(encHex, password) {
4
- const data = Buffer.from(encHex, "hex");
5
- const salt = data.subarray(0, 16);
6
- const iv = data.subarray(16, 28);
7
- const tag = data.subarray(28, 44);
8
- const encrypted = data.subarray(44);
9
- const key = scryptSync(password, salt, 32);
10
- const decipher = createDecipheriv("aes-256-gcm", key, iv);
11
- decipher.setAuthTag(tag);
12
- return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
13
- }
14
- //# sourceMappingURL=decrypt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decrypt.js","sourceRoot":"","sources":["../../src/crypto-symmetricaly/decrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAEV,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAEhB,UAAU;AACV,MAAM,UAAU,OAAO,CAAC,MAAc,EAAE,QAAgB;IACtD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAEpC,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,gBAAgB,CAAC,aAAa,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IAC1D,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAEzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAC3E,MAAM,CACP,CAAC;AACJ,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function encrypt(text: string, password: string): string;
2
- //# sourceMappingURL=encrypt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encrypt.d.ts","sourceRoot":"","sources":["../../src/crypto-symmetricaly/encrypt.ts"],"names":[],"mappings":"AAQA,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAarD"}