mescp-flow 0.0.1
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/README.md +7 -0
- package/bin/package-extract.js +73 -0
- package/encrypted/mes-files.tar.enc +0 -0
- package/index.js +5 -0
- package/package.json +21 -0
- package/scripts/extract.js +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const crypto = require('crypto');
|
|
6
|
+
const tar = require('tar');
|
|
7
|
+
const { execSync } = require('child_process');
|
|
8
|
+
|
|
9
|
+
// 从环境变量获取加密密钥
|
|
10
|
+
const encKey = process.env.MES_ENCRYPTION_KEY;
|
|
11
|
+
if (!encKey) {
|
|
12
|
+
console.error('错误: 缺少环境变量 MES_ENCRYPTION_KEY。请设置此环境变量后再运行。');
|
|
13
|
+
console.error('提示: 您可以使用以下命令设置环境变量:');
|
|
14
|
+
console.error(' export MES_ENCRYPTION_KEY=您的密钥');
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 确保密钥是64字符长度
|
|
19
|
+
const ENCRYPTION_KEY = encKey.padEnd(64, '0');
|
|
20
|
+
// 设置与加密时相同的IV值
|
|
21
|
+
const IV = Buffer.from('00000000000000000000000000000000', 'hex');
|
|
22
|
+
|
|
23
|
+
// 路径设置
|
|
24
|
+
const pkgPath = path.resolve(__dirname, '..');
|
|
25
|
+
const encryptedFilePath = path.join(pkgPath, 'encrypted/mes-files.tar.enc');
|
|
26
|
+
const projectRoot = process.cwd(); // 获取当前工作目录
|
|
27
|
+
|
|
28
|
+
console.log('开始解密并提取 MesCP 文件...');
|
|
29
|
+
console.log('解压到目录: ' + projectRoot);
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// 读取加密文件
|
|
33
|
+
const encryptedData = fs.readFileSync(encryptedFilePath);
|
|
34
|
+
|
|
35
|
+
// 创建解密器
|
|
36
|
+
const decipher = crypto.createDecipheriv(
|
|
37
|
+
'aes-256-cbc',
|
|
38
|
+
Buffer.from(ENCRYPTION_KEY, 'hex'),
|
|
39
|
+
IV
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
// 解密数据
|
|
44
|
+
let decryptedData = Buffer.concat([
|
|
45
|
+
decipher.update(encryptedData),
|
|
46
|
+
decipher.final()
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
// 保存解密后的 tar 文件
|
|
50
|
+
const tempTarPath = path.join(pkgPath, 'encrypted/mes-files.tar');
|
|
51
|
+
fs.writeFileSync(tempTarPath, decryptedData);
|
|
52
|
+
|
|
53
|
+
// 解压文件到当前项目目录,保持原有目录结构
|
|
54
|
+
tar.extract({
|
|
55
|
+
file: tempTarPath,
|
|
56
|
+
cwd: projectRoot // 解压到项目根目录,保持原有目录结构
|
|
57
|
+
}).then(() => {
|
|
58
|
+
console.log('文件解压完成');
|
|
59
|
+
// 删除临时文件
|
|
60
|
+
fs.unlinkSync(tempTarPath);
|
|
61
|
+
console.log('解压操作完成');
|
|
62
|
+
}).catch(err => {
|
|
63
|
+
console.error('解压文件时出错:', err);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('解密失败: 提供的密钥不正确。请确认环境变量 MES_ENCRYPTION_KEY 的值是否正确。');
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('处理文件时出错:', error);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
Binary file
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mescp-flow",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "MesCP 加密文件包",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"extract": "./bin/package-extract.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"extract": "node bin/package-extract.js"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"mes-framework",
|
|
14
|
+
"binary"
|
|
15
|
+
],
|
|
16
|
+
"author": "MesCP Team",
|
|
17
|
+
"license": "proprietary",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"tar": "^6.1.11"
|
|
20
|
+
}
|
|
21
|
+
}
|