Registration and activation
This commit is contained in:
16
backend/utils/crypto.js
Normal file
16
backend/utils/crypto.js
Normal 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();
|
||||
};
|
||||
Reference in New Issue
Block a user