crypto: rename sha256 func to generateHmac

it has always been actually hmac
This commit is contained in:
wukko 2024-03-05 20:55:17 +06:00
parent 9211b39588
commit 6ed03b0035
3 changed files with 7 additions and 7 deletions

View file

@ -10,7 +10,7 @@ import { apiJSON, checkJSONPost, getIP, languageCode } from "../modules/sub/util
import { Bright, Cyan } from "../modules/sub/consoleText.js";
import stream from "../modules/stream/stream.js";
import loc from "../localization/manager.js";
import { sha256 } from "../modules/sub/crypto.js";
import { generateHmac } from "../modules/sub/crypto.js";
import { verifyStream } from "../modules/stream/manage.js";
export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
@ -24,7 +24,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
max: 20,
standardHeaders: true,
legacyHeaders: false,
keyGenerator: req => sha256(getIP(req), ipSalt),
keyGenerator: req => generateHmac(getIP(req), ipSalt),
handler: (req, res, next, opt) => {
return res.status(429).json({
"status": "rate-limit",
@ -37,7 +37,7 @@ export function runAPI(express, app, gitCommit, gitBranch, __dirname) {
max: 25,
standardHeaders: true,
legacyHeaders: false,
keyGenerator: req => sha256(getIP(req), ipSalt),
keyGenerator: req => generateHmac(getIP(req), ipSalt),
handler: (req, res, next, opt) => {
return res.status(429).json({
"status": "rate-limit",

View file

@ -2,7 +2,7 @@ import NodeCache from "node-cache";
import { randomBytes } from "crypto";
import { nanoid } from 'nanoid';
import { decryptStream, encryptStream, sha256 } from "../sub/crypto.js";
import { decryptStream, encryptStream, generateHmac } from "../sub/crypto.js";
import { streamLifespan } from "../config.js";
const streamCache = new NodeCache({
@ -22,7 +22,7 @@ export function createStream(obj) {
iv = randomBytes(16).toString('base64'),
secret = randomBytes(256).toString('base64'),
exp = new Date().getTime() + streamLifespan,
hmac = sha256(`${streamID},${exp},${iv},${secret}`, hmacSalt),
hmac = generateHmac(`${streamID},${exp},${iv},${secret}`, hmacSalt),
streamData = {
exp: exp,
type: obj.type,
@ -60,7 +60,7 @@ export function createStream(obj) {
export function verifyStream(id, hmac, exp, secret, iv) {
try {
const ghmac = sha256(`${id},${exp},${iv},${secret}`, hmacSalt);
const ghmac = generateHmac(`${id},${exp},${iv},${secret}`, hmacSalt);
if (ghmac !== String(hmac)) {
return {

View file

@ -3,7 +3,7 @@ import { createHmac, createCipheriv, createDecipheriv, scryptSync } from "crypto
const algorithm = "aes256"
const keyLength = 32;
export function sha256(str, salt) {
export function generateHmac(str, salt) {
return createHmac("sha256", salt).update(str).digest("base64");
}