Skip to content

Commit f8ccf4c

Browse files
author
lucifer
committed
fix: iv
1 parent 26315ad commit f8ccf4c

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

routes/users.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const secret = process.env.secret;
66

77
const clientId = "c16b80e7b58a5a007157";
88
const algorithm = "aes-256-ctr";
9-
const iv = crypto.randomBytes(16);
9+
const iv = crypto.randomBytes(16).toString("hex");
1010

1111
const db = [
1212
{
@@ -19,21 +19,18 @@ function encrypt(text) {
1919

2020
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
2121

22-
return {
23-
iv: iv.toString("hex"),
24-
content: encrypted.toString("hex"),
25-
};
22+
return encrypted.toString("hex");
2623
}
2724

28-
function decrypt(hash) {
25+
function decrypt(content) {
2926
const decipher = crypto.createDecipheriv(
3027
algorithm,
3128
secret.slice(0, 32),
32-
Buffer.from(hash, iv, "hex")
29+
Buffer.from(iv, "hex")
3330
);
3431

3532
const decrpyted = Buffer.concat([
36-
decipher.update(Buffer.from(hash.content, "hex")),
33+
decipher.update(Buffer.from(content, "hex")),
3734
decipher.final(),
3835
]);
3936

0 commit comments

Comments
 (0)