/
aat
/
sreda.v2
Обзор
Документация
Войти
/
aat
/
sreda.v2
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
back/scripts/crypto.cjs
48 строк
2 KB
Alex
upd
15 апр 2026, 22:14
15 апр 2026, 22:14
e4b93ad
Код
Авторство
О чём код?
'use strict' const fs = require('fs'); // библиотека для работы с файлами const crypto = require('crypto'); // встроенный модуль node.js для криптографии // Входной файл и выходной файл const inputFilePath = './index.o.js'; const outputFilePath = './index.bin.js'; // Чтение содержимого файла и передача его через поток шифрования let data = fs.readFileSync(inputFilePath,"utf-8"); const salt = crypto.randomBytes(16).toString('hex'); // Generate a random salt const algorithm = 'aes-256-cbc'; const key = Buffer.from('1234567890-1234567890-1234567890'); //crypto.randomBytes(32); const iv = Buffer.from('d617ca6e4f47ceeb5f4a61b759411913', 'hex'); // const iv = crypto.randomBytes(16); function encrypt(text) { let cipher = crypto.createCipheriv(algorithm, Buffer.from(key), iv); let encrypted = cipher.update(text); encrypted = Buffer.concat([encrypted, cipher.final()]); return { iv: iv.toString('hex'), encryptedData: encrypted.toString('hex') }; } // const secretKey = 'my_secret_key'; // data = data.replaceAll('export default Owner', '') //костыль export'ов не должно быть const сData = encrypt(data); console.log('Encrypted Data:', salt, сData); fs.writeFileSync(outputFilePath, Buffer.from(сData.encryptedData)); //`export default "${сData.encryptedData}"` function decrypt(text) { let iv = Buffer.from(text.iv, 'hex'); let encryptedText = Buffer.from(text.encryptedData, 'hex'); let decipher = crypto.createDecipheriv(algorithm, Buffer.from(key), iv); let decrypted = decipher.update(encryptedText); decrypted = Buffer.concat([decrypted, decipher.final()]); return decrypted.toString(); } const dData = decrypt(сData); fs.writeFileSync('index.d.js', Buffer.from(dData));