const CryptoJS = require('crypto-js'); const fs = require('fs'); // 读取原始 HTML const originalHtml = fs.readFileSync('nav-home.html', 'utf8'); // 使用密码加密 const password = 'joylodging'; const encrypted = CryptoJS.AES.encrypt(originalHtml, password).toString(); // 读取模板 let template = fs.readFileSync('nav-home-encrypted.html', 'utf8'); // 使用正则替换已有的加密内容(匹配 const ENCRYPTED_CONTENT = "..." 格式) template = template.replace( /const ENCRYPTED_CONTENT = "[^"]*";/, `const ENCRYPTED_CONTENT = "${encrypted}";` ); // 写入最终文件 fs.writeFileSync('nav-home-encrypted.html', template); console.log('Encryption complete!'); console.log('Encrypted content length:', encrypted.length); console.log('First 100 chars:', encrypted.substring(0, 100));