diff --git a/server/src/utils/auth.ts b/server/src/utils/auth.ts index 96e121f9..2468fe53 100644 --- a/server/src/utils/auth.ts +++ b/server/src/utils/auth.ts @@ -1,4 +1,5 @@ import bcrypt from "bcrypt"; +import crypto from 'crypto'; export const hashPassword = (password: string): Promise => { return new Promise((resolve, reject) => { @@ -19,4 +20,12 @@ export const hashPassword = (password: string): Promise => { // password from frontend and hash from database export const comparePassword = (password: string, hash: string): Promise => { return bcrypt.compare(password, hash) -} \ No newline at end of file +} + +const encrypt = (text: string): string => { + const iv = crypto.randomBytes(IV_LENGTH); + const cipher = crypto.createCipheriv(ALGORITHM, Buffer.from(ENCRYPTION_KEY), iv); + let encrypted = cipher.update(text, 'utf8', 'hex'); + encrypted += cipher.final('hex'); + return `${iv.toString('hex')}:${encrypted}`; +}; \ No newline at end of file