Registration and activation

This commit is contained in:
Torsten Schulz
2024-07-20 20:43:18 +02:00
parent 3880a265eb
commit bbf4a2deb3
51 changed files with 3016 additions and 69 deletions

16
backend/utils/crypto.js Normal file
View File

@@ -0,0 +1,16 @@
import crypto from 'crypto';
const algorithm = 'aes-256-ctr';
const secretKey = process.env.SECRET_KEY;
export const encrypt = (text) => {
const cipher = crypto.createCipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
const encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
return encrypted.toString('hex');
};
export const decrypt = (hash) => {
const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.alloc(16, 0));
const decrpyted = Buffer.concat([decipher.update(Buffer.from(hash, 'hex')), decipher.final()]);
return decrpyted.toString();
};