This commit is contained in:
2023-05-02 01:51:09 -04:00
parent fda0e160d4
commit 14fe45fc9c
2 changed files with 14 additions and 14 deletions

View File

@@ -1,12 +1,12 @@
import crypto from 'crypto';
import { pbkdf2Sync, randomBytes } from 'crypto';
export const encrypt = (password: string) => {
const salt = crypto.randomBytes(16).toString('hex');
const hash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex');
const salt = randomBytes(16).toString('hex');
const hash = pbkdf2Sync(password, salt, 10000, 512, 'sha512').toString('hex');
return `${salt}:${hash}`;
};
export const verify = (test: string, secret: string) => {
const [salt, hash] = secret.split(':');
return crypto.pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash;
return pbkdf2Sync(test, salt, 10000, 512, 'sha512').toString('hex') === hash;
};