Skip to content

Commit 2e26ca2

Browse files
committed
Enhance performance with MD5
1 parent c81f269 commit 2e26ca2

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
"eslint": "^8.12.0",
2121
"eslint-config-prettier": "^8.5.0",
2222
"mocha": "^9.2.2",
23-
"prettier": "^2.6.2",
23+
"prettier": "^2.6.2"
24+
},
25+
"dependencies": {
2426
"uuid": "^9.0.0"
2527
}
2628
}

src/libs/decrypt.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ const crypto = require("crypto");
22
const options = require("../options");
33

44
function decrypt(key, hash) {
5-
const { salt, algorithm } = options();
6-
const buffer = crypto.scryptSync(key, salt, 32);
5+
const { algorithm } = options();
76
const parts = hash.split(":");
87
const iv = Buffer.from(parts.shift(), "hex");
98
const en = Buffer.from(parts.join(":"), "hex");
9+
1010
const decipher = crypto.createDecipheriv(
1111
algorithm,
12-
Buffer.from(buffer, "hex"),
12+
crypto.createHash("md5").update(key).digest("hex"),
1313
iv
1414
);
1515

src/libs/encrypt.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ const crypto = require("crypto");
22
const options = require("../options");
33

44
function encrypt(key, data) {
5-
const { salt, algorithm } = options();
6-
const buffer = crypto.scryptSync(key, salt, 32);
7-
5+
const { algorithm } = options();
86
const iv = crypto.randomBytes(16);
7+
98
const cipher = crypto.createCipheriv(
109
algorithm,
11-
Buffer.from(buffer, "hex"),
10+
crypto.createHash("md5").update(key).digest("hex"),
1211
iv
1312
);
1413

src/options.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ const uuid = require("uuid").v4;
22
const home = require("os").homedir();
33

44
let _options = {
5-
key: "0c3Yc2KDj0rQWq9aJEnOGNzsNb4IrHPq",
6-
salt: "UqD4yJPYL5gkbJZsahPJItNiQYNoiN20",
5+
key: "EOsDDQ1zovGCl0iTZUxRmrks1GM86jRX",
76
algorithm: "aes-256-ctr",
87
};
98

0 commit comments

Comments
 (0)