const crypto = require('crypto');
const DEFAULT_KEY="minglie@network1";
class AESUtils {
static encrypt(data, key=DEFAULT_KEY) {
const cipher = crypto.createCipheriv('aes-128-ecb', key, Buffer.from(''));
let encrypted = cipher.update(data, 'utf8', 'base64');
encrypted += cipher.final('base64');
return encrypted;
}
static decrypt(encryptedData, key=DEFAULT_KEY) {
const decipher = crypto.createDecipheriv('aes-128-ecb', key, Buffer.from(''));
let decrypted = decipher.update(encryptedData, 'base64', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
}
const data = "Hello, Worlddddddddd!";
const encryptedData = AESUtils.encrypt(data);
console.log('Encrypted Data:', encryptedData);
const decryptedData = AESUtils.decrypt(encryptedData);
console.log('Decrypted Data:', decryptedData);
module.exports = AESUtils;