igoercopy1 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/decrypt.js ADDED
@@ -0,0 +1,44 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const CryptoJS = require('crypto-js');
4
+
5
+ // 配置项
6
+ const CONFIG = {
7
+ SECRET_KEY: '', // 解密密钥(需和加密密钥一致)
8
+ ENCRYPTED_FILE: './encrypted-folder.data', // 加密文件路径
9
+ DECRYPT_FOLDER: './decrypted-folder' // 解密后输出文件夹
10
+ };
11
+
12
+ // 解密核心逻辑
13
+ function decryptFolder() {
14
+ try {
15
+ if (!CONFIG.SECRET_KEY) {
16
+ throw new Error('请通过环境变量 DECRYPT_KEY 传入解密密钥');
17
+ }
18
+
19
+ // 1. 读取加密文件
20
+ const encryptedData = fs.readFileSync(CONFIG.ENCRYPTED_FILE, 'utf8');
21
+ // 2. AES解密
22
+ const decryptedBytes = CryptoJS.AES.decrypt(encryptedData, CONFIG.SECRET_KEY);
23
+ const folderData = JSON.parse(decryptedBytes.toString(CryptoJS.enc.Utf8));
24
+ // 3. 还原文件夹和文件
25
+ if (!fs.existsSync(CONFIG.DECRYPT_FOLDER)) {
26
+ fs.mkdirSync(CONFIG.DECRYPT_FOLDER, { recursive: true });
27
+ }
28
+ for (const file of folderData) {
29
+ const fullPath = path.join(CONFIG.DECRYPT_FOLDER, file.path);
30
+ // 创建文件所在的目录
31
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
32
+ // 写入文件内容
33
+ fs.writeFileSync(fullPath, Buffer.from(file.content));
34
+ }
35
+
36
+ console.log(`✅ 文件夹解密成功!输出路径:${CONFIG.DECRYPT_FOLDER}`);
37
+ } catch (error) {
38
+ console.error('❌ 解密失败:', error.message);
39
+ process.exit(1);
40
+ }
41
+ }
42
+
43
+ // 执行解密
44
+ decryptFolder();