Skip to content

Commit 25e8204

Browse files
committed
security: replace HMAC-SHA256 with scrypt for API key hashing
1 parent 2946ae9 commit 25e8204

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

‎backend/utils/api.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ function generateApiKey() {
1515

1616
//api hashing
1717
function hashApiKey(apikey) {
18-
return crypto
19-
.createHmac("sha256", "ikewdxnuuencwoi")
20-
.update(apikey)
21-
.digest("hex");
18+
// scrypt hashing: fast but brute focre resistant
19+
// 'salt' को .env में रखना बेहतर है
20+
const salt = process.env.API_KEY_SALT;
21+
22+
// generate a derived key of 64 bytes
23+
return crypto.scryptSync(apikey, salt, 64).toString('hex');
2224
}
2325

2426
module.exports = { generateApiKey, hashApiKey }

0 commit comments

Comments
 (0)