提交 a919c701 编写于 作者: W weixin_43888397

Auto Commit

上级 ca207a2f
console.log("欢迎来到 InsCode");
\ No newline at end of file
{ pkgs }: {
deps = [
pkgs.nodejs-18_x
pkgs.yarn
];
}
\ No newline at end of file
{
"name": "nodejs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^18.0.6",
"node-fetch": "^3.2.6"
}
}
\ No newline at end of file
run = "npm i && npm run dev"
[env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
\ No newline at end of file
run = "npm i && npm run dev"
language = "node"
[env]
PATH = "/root/${PROJECT_DIR}/.config/npm/node_global/bin:/root/${PROJECT_DIR}/node_modules/.bin:${PATH}"
XDG_CONFIG_HOME = "/root/.config"
npm_config_prefix = "/root/${PROJECT_DIR}/.config/npm/node_global"
[debugger]
program = "main.js"
\ No newline at end of file
{
"name": "tool",
"version": "1.0.0",
"description": "",
"main": "src/codec.js",
"scripts": {
"test": "echo \"Error: no codec specified\" && exit 1",
"decode": "node ./src/codec.js -decode ./test/config.db ./test/text.json"
},
"dependencies": {
"crypto-js": "^4.2.0"
},
"keywords": [],
"author": "",
"license": "ISC"
}
\ No newline at end of file
# 编解码配置文件说明
## 环境搭建教程
*环境搭建教程:*
cd到tool目录,安装node 依赖,执行命令
```
npm install
```
## 解码某个加密配置文件,输出到某个json文件
执行加解密js脚本,输入解码命令'-decode', 输入文件及输出文件,如下:
```
node ./src/codec.js -decode ./test/config.db ./test/config.json
```
## 加密json文件,输出到某个文件
执行加解密js脚本,输入加密命令'-encode', 输入文件及输出文件,如下:
*如:*
```
node ./src/codec.js -encode ./test/config.json ./test/config.db
```
var CryptoJS = require('crypto-js');
var fs = require('fs');
var path = require('path');
// 十六位十六进制数作为密钥
const SECRET_KEY ='xlgameaccelerate';
// 十六位十六进制数作为密钥偏移量
const SECRET_IV = 'xlgameaccelerate';
// 解密方法
function Decrypt(word) {
const secretKey = CryptoJS.enc.Utf8.parse(SECRET_KEY);
const secretIv = CryptoJS.enc.Utf8.parse(SECRET_IV);
var decrypt = CryptoJS.AES.decrypt(word, secretKey, { iv: secretIv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
var decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
return decryptedStr.toString();
}
// 加密方法
function Encrypt(word) {
const key = CryptoJS.enc.Utf8.parse(SECRET_KEY);
const secretIv = CryptoJS.enc.Utf8.parse(SECRET_IV);
var srcs = CryptoJS.enc.Utf8.parse(word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: secretIv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
return encrypted.toString();
}
// 解密文件
function decodeFile(targetFile, outFile) {
if(!targetFile){
console.log('The input file is empty');
return;
}
if(!outFile){
console.log('The output file is empty');
return;
}
var fileData = '';
try {
fileData = fs.readFileSync( targetFile, "utf8");
} catch(err){
console.log("Read file eror, targetFile:", targetFile);
}
console.log('Target file data:', fileData);
var bufferData = fileData.toString();
bufferData = Decrypt(bufferData);
var configData = JSON.parse(bufferData);
console.log('Target file decode :', configData);
if(configData){
try {
var jsonStr = JSON.stringify(configData, undefined, 2);
fs.writeFileSync( outFile, jsonStr, {"encoding":'utf8'});
console.log("Decode success! outFile:", outFile);
} catch(err){
console.log("Decode error! outFile:", outFile);
}
}
}
// 加密文件
function encodeFile(targetFile, outFile) {
if(!targetFile){
console.log('The input file is empty');
return;
}
if(!outFile){
console.log('The output file is empty');
return;
}
var fileData = '';
try {
fileData = fs.readFileSync( targetFile, "utf8");
} catch(err){
console.log("Read file eror, targetFile:", targetFile);
}
console.log('Target file data:', fileData);
var bufferData = fileData.toString();
var configData = '';
var jsonStr = '';
try {
configData = JSON.parse(bufferData);
console.log("Parse Target file successed! targetFile:", targetFile);
} catch(err){
cconsole.log("Parse Target file error! targetFile:", targetFile);
}
if(configData){
jsonStr = JSON.stringify(configData, undefined, 2);
jsonStr = Encrypt(jsonStr);
console.log('Target file encrypt data:', jsonStr);
}
if(jsonStr){
try {
fs.writeFileSync( outFile, jsonStr, {"encoding":'utf8'});
console.log("Encode success! outFile:", outFile);
} catch(err){
console.log("Encode error! outFile:", outFile);
}
}
}
function main(){
var argv = process.argv;
if(argv.length < 5) {
console.log('Less than 3 parameters! Please enter command, input file, output file');
return;
}
var strCommand = argv[2];
var strTargetFilePath = argv[3];
var strOutFilePath = argv[4];
if(strCommand === '-decode') {
decodeFile(strTargetFilePath, strOutFilePath);
} else if(strCommand === '-encode'){
encodeFile(strTargetFilePath, strOutFilePath);
}
}
main();
eI9crakxmmK54IHBGoxN7xJwnQ29/Dg1EG12GMxSPKuXBrpw4f4osjXydGYqPMOV
\ No newline at end of file
{
"test1": "11111",
"test2": "22222"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册