@8ms/helpers 2.4.3 → 2.4.4
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,15 +1,15 @@
|
|
|
1
1
|
import { t as __require } from "../../chunk-y_GBKt04.mjs";
|
|
2
2
|
import { getString } from "../../string/index.mjs";
|
|
3
|
+
import * as crypto from "crypto";
|
|
3
4
|
//#region src/crypto/server/getDecrypt.ts
|
|
4
5
|
/**
|
|
5
6
|
* Decrypt an encoding string using a salt.
|
|
6
7
|
*/
|
|
7
8
|
const getDecrypt = (appSalt, input, salt) => {
|
|
8
|
-
const crypto = __require("crypto");
|
|
9
9
|
const ALGORITHM = "aes-256-cbc";
|
|
10
10
|
const customSalt = `${appSalt}-${salt}`;
|
|
11
11
|
const [ivHex, encryptedHex] = input.split(":");
|
|
12
|
-
const key = crypto.
|
|
12
|
+
const key = crypto.pbkdf2Sync(customSalt, "salt", 1e5, 32, "sha256");
|
|
13
13
|
const iv = Buffer.from(ivHex, "hex");
|
|
14
14
|
const encrypted = Buffer.from(encryptedHex, "hex");
|
|
15
15
|
const decipher = crypto.createDecipheriv(ALGORITHM, key, iv);
|
|
@@ -21,10 +21,9 @@ const getDecrypt = (appSalt, input, salt) => {
|
|
|
21
21
|
* Encrypt an encoding string using a salt.
|
|
22
22
|
*/
|
|
23
23
|
const getEncrypt = (appSalt, input, salt) => {
|
|
24
|
-
const crypto = __require("crypto");
|
|
25
24
|
const ALGORITHM = "aes-256-cbc";
|
|
26
25
|
const customSalt = `${appSalt}-${salt}`;
|
|
27
|
-
const key = crypto.
|
|
26
|
+
const key = crypto.pbkdf2Sync(customSalt, "salt", 1e5, 32, "sha256");
|
|
28
27
|
const iv = crypto.randomBytes(16);
|
|
29
28
|
const cipher = crypto.createCipheriv(ALGORITHM, key, iv);
|
|
30
29
|
const encrypted = Buffer.concat([cipher.update(input, "utf8"), cipher.final()]);
|