This is a simple example, please consider using createHash instead for passwords in production
const crypto = require('crypto');
const passwordToEncrypt = "AP34IOUR+&"
const salt = "My Awesome Salt"
function encryptData(salt, passwordToEncrypt){
const cipher = crypto.createCipher('aes256', salt);
let encrypted = cipher.update(passwordToEncrypt, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
function decryptData(salt, encryptedPassword){
const decipher = crypto.createDecipher('aes256', salt);
let decrypted = decipher.update(encryptedPassword, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted
}
const encryptedData = encryptData(salt, passwordToEncrypt)
console.log('Encrypted Data :', encryptedData)
const decryptedData = decryptData(salt, encryptedPassword)
console.log('Decrypted Data :', decryptedData)