Skip to content

Commit 7a4cd0b

Browse files
author
lucifer
committed
fix: secret length should be 32 byte
1 parent 7a55edb commit 7a4cd0b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

routes/users.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const db = [
1515
];
1616

1717
function encrypt(text) {
18-
const cipher = crypto.createCipheriv(algorithm, secret, iv);
18+
const cipher = crypto.createCipheriv(algorithm, secret.slice(0, 32), iv);
1919

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

@@ -28,7 +28,7 @@ function encrypt(text) {
2828
function decrypt(hash) {
2929
const decipher = crypto.createDecipheriv(
3030
algorithm,
31-
secret,
31+
secret.slice(0, 32),
3232
Buffer.from(hash.iv, "hex")
3333
);
3434

0 commit comments

Comments
 (0)