@8ms/helpers 2.4.4 → 2.4.5

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.
@@ -1,14 +1,20 @@
1
1
  //#region src/crypto/server/getDecrypt.d.ts
2
2
  /**
3
3
  * Decrypt an encoding string using a salt.
4
+ * @param salt32 must be 32 bytes
5
+ * @param salt16 must be 16 bytes
6
+ * @param input any string
4
7
  */
5
- declare const getDecrypt: (appSalt: string, input: string, salt: string) => string;
8
+ declare const getDecrypt: (salt32: string, salt16: string, input: string) => string;
6
9
  //#endregion
7
10
  //#region src/crypto/server/getEncrypt.d.ts
8
11
  /**
9
12
  * Encrypt an encoding string using a salt.
13
+ * @param salt32 must be 32 bytes
14
+ * @param salt16 must be 16 bytes
15
+ * @param input any string
10
16
  */
11
- declare const getEncrypt: (appSalt: string, input: string, salt: string) => string;
17
+ declare const getEncrypt: (salt32: string, salt16: string, input: string) => string;
12
18
  //#endregion
13
19
  //#region src/crypto/server/getMd5.d.ts
14
20
  /**
@@ -4,30 +4,29 @@ import * as crypto from "crypto";
4
4
  //#region src/crypto/server/getDecrypt.ts
5
5
  /**
6
6
  * Decrypt an encoding string using a salt.
7
+ * @param salt32 must be 32 bytes
8
+ * @param salt16 must be 16 bytes
9
+ * @param input any string
7
10
  */
8
- const getDecrypt = (appSalt, input, salt) => {
9
- const ALGORITHM = "aes-256-cbc";
10
- const customSalt = `${appSalt}-${salt}`;
11
- const [ivHex, encryptedHex] = input.split(":");
12
- const key = crypto.pbkdf2Sync(customSalt, "salt", 1e5, 32, "sha256");
13
- const iv = Buffer.from(ivHex, "hex");
14
- const encrypted = Buffer.from(encryptedHex, "hex");
15
- const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
16
- return Buffer.concat([decipher.update(encrypted), decipher.final()]).toString("utf8");
11
+ const getDecrypt = (salt32, salt16, input) => {
12
+ const decipher = crypto.createDecipheriv("aes-256-cbc", salt32, salt16);
13
+ let decrypted = decipher.update(input, "hex", "utf8");
14
+ decrypted += decipher.final("utf8");
15
+ return decrypted;
17
16
  };
18
17
  //#endregion
19
18
  //#region src/crypto/server/getEncrypt.ts
20
19
  /**
21
20
  * Encrypt an encoding string using a salt.
21
+ * @param salt32 must be 32 bytes
22
+ * @param salt16 must be 16 bytes
23
+ * @param input any string
22
24
  */
23
- const getEncrypt = (appSalt, input, salt) => {
24
- const ALGORITHM = "aes-256-cbc";
25
- const customSalt = `${appSalt}-${salt}`;
26
- const key = crypto.pbkdf2Sync(customSalt, "salt", 1e5, 32, "sha256");
27
- const iv = crypto.randomBytes(16);
28
- const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
29
- const encrypted = Buffer.concat([cipher.update(input, "utf8"), cipher.final()]);
30
- return iv.toString("hex") + ":" + encrypted.toString("hex");
25
+ const getEncrypt = (salt32, salt16, input) => {
26
+ const cipher = crypto.createCipheriv("aes-256-cbc", salt32, salt16);
27
+ let encrypted = cipher.update(input, "utf8", "hex");
28
+ encrypted += cipher.final("hex");
29
+ return encrypted;
31
30
  };
32
31
  //#endregion
33
32
  //#region src/crypto/server/getMd5.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.4",
4
+ "version": "2.4.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -11,10 +11,6 @@
11
11
  "build": "tsdown",
12
12
  "jest": "jest --watch"
13
13
  },
14
- "packageManager": "yarn@4.12.0",
15
- "engines": {
16
- "node": "24"
17
- },
18
14
  "dependencies": {
19
15
  "fs-extra": "^11.0.0",
20
16
  "ky": "^2.0.0",