Files
crm-server/scripts/encrypt-password.js
2025-11-18 13:53:28 +01:00

26 lines
814 B
JavaScript

import crypto from 'crypto';
const encryptPassword = (text) => {
const algorithm = 'aes-256-gcm';
const key = crypto.scryptSync(process.env.JWT_SECRET || 'your-super-secret-jwt-key-change-this-in-production', 'salt', 32);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
const authTag = cipher.getAuthTag();
return `${iv.toString('hex')}:${authTag.toString('hex')}:${encrypted}`;
};
// Usage: node scripts/encrypt-password.js YOUR_PASSWORD
const password = process.argv[2];
if (!password) {
console.error('Usage: node scripts/encrypt-password.js YOUR_PASSWORD');
process.exit(1);
}
console.log('Encrypted password:');
console.log(encryptPassword(password));