feat: script per criptare frasi motivazionali/demotivazionali e spostate all'interno del sqllite. Mantenuti file txt per compatibilità. Aggiunta soglia di attivazione nel env

This commit is contained in:
2026-07-08 03:09:44 +02:00
parent e6c3a6a43f
commit d39c9895b4
7 changed files with 208 additions and 13 deletions
+30
View File
@@ -0,0 +1,30 @@
const crypto = require('crypto');
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '../.env') });
const ALGORITHM = 'aes-256-cbc';
const SECRET_KEY = crypto.createHash('sha256').update(process.env.CRYPTO_KEY || 'default_secret_key_12345').digest();
const encryptedText = process.argv[2];
if (!encryptedText) {
console.log('Utilizzo: node decrypt.js "testo_criptato:valore"');
process.exit(1);
}
try {
const textParts = encryptedText.split(':');
if (textParts.length < 2) {
throw new Error('Formato testo cifrato non valido (manca il separatore ":")');
}
const iv = Buffer.from(textParts.shift(), 'hex');
const encrypted = Buffer.from(textParts.join(':'), 'hex');
const decipher = crypto.createDecipheriv(ALGORITHM, SECRET_KEY, iv);
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log('Testo Criptato: ', encryptedText);
console.log('Testo Decriptato:', decrypted);
} catch (err) {
console.error('Errore durante la decriptazione:', err.message);
process.exit(1);
}
+22
View File
@@ -0,0 +1,22 @@
const crypto = require('crypto');
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '../.env') });
const ALGORITHM = 'aes-256-cbc';
const SECRET_KEY = crypto.createHash('sha256').update(process.env.CRYPTO_KEY || 'default_secret_key_12345').digest();
const IV_LENGTH = 16;
const text = process.argv[2];
if (!text) {
console.log('Utilizzo: node encrypt.js "testo da criptare"');
process.exit(1);
}
const iv = crypto.randomBytes(IV_LENGTH);
const cipher = crypto.createCipheriv(ALGORITHM, SECRET_KEY, iv);
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
const result = iv.toString('hex') + ':' + encrypted;
console.log('Testo Originale:', text);
console.log('Testo Criptato: ', result);