En-/decryption fixed
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import crypto from 'crypto';
|
||||
|
||||
const algorithm = 'aes-256-cbc';
|
||||
const secretKey = process.env.SECRET_KEY;
|
||||
const algorithm = 'aes-256-ecb';
|
||||
const key = crypto.scryptSync(process.env.SECRET_KEY, 'salt', 32);
|
||||
|
||||
export const generateIv = () => {
|
||||
return crypto.randomBytes(16);
|
||||
};
|
||||
|
||||
export const encrypt = (text, iv) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, Buffer.from(secretKey, 'utf-8'), iv);
|
||||
export const encrypt = (text) => {
|
||||
const cipher = crypto.createCipheriv(algorithm, key, null);
|
||||
let encrypted = cipher.update(text, 'utf8', 'hex');
|
||||
encrypted += cipher.final('hex');
|
||||
return encrypted;
|
||||
};
|
||||
|
||||
export const decrypt = (text, iv) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, Buffer.from(secretKey, 'utf-8'), iv);
|
||||
export const decrypt = (text) => {
|
||||
const decipher = crypto.createDecipheriv(algorithm, key, null);
|
||||
let decrypted = decipher.update(text, 'hex', 'utf8');
|
||||
decrypted += decipher.final('utf8');
|
||||
return decrypted;
|
||||
|
||||
Reference in New Issue
Block a user