提交 f8ad0292 authored 作者: 钟是志's avatar 钟是志

二进制加密增加混淆代码

上级 3ce3a958
import { apiRequest } from '@/webPublic/one_stop_public/utils/request';
import { isJSON } from '@/webPublic/zyd_public/utils/utils';
import baseX from 'base-x';
import encryptApiList from '@/webPublic/one_stop_public/Base16/encryptApiList';
var BASE16 = '0123456789abcdef';
var bs16 = baseX(BASE16);
function checkOpenBase16() {
const is_open_base14 = sessionStorage.getItem('is_open_base16')
? JSON.parse(sessionStorage.getItem('is_open_base16'))
: false;
return is_open_base14;
}
export function Base16Encode(value) {
const is_open_base14 = checkOpenBase16();
if (is_open_base14) {
if (!value) {
return null;
} else {
let newV = new Buffer(value); // 快
const r = bs16.encode(newV); // 慢
return r;
}
}
return value;
}
function giveKey(key, datas) {
if (datas && datas[key]) {
datas[key] = Base16Encode(datas[key]);
}
return datas;
}
async function countAllValues(datas, item) {
if (item.setNull) {
datas.allValues = JSON.stringify({});
} else {
if (item.query) {
if (datas?.sqlKey.length < 13) {
const response = await apiRequest('/SqlManageEntityApi/findParamsKey', {
sqlKey: datas.sqlKey,
});
if (!response || (Array.isArray(response) && response.length === 0)) {
datas.allValues = JSON.stringify({});
} else {
const x = (isJSON(datas.allValues) && JSON.parse(datas.allValues)) || {};
const y = {};
for (let i of response) {
if (x[i]) {
y[i] = x[i];
}
datas.allValues = JSON.stringify(y);
}
}
} else {
datas.allValues = JSON.stringify({});
}
}
}
return datas;
}
export async function giveBase16EncodeAsync(datas, url) {
if (!checkOpenBase16()) {
return datas;
}
if (url && typeof url === 'string') {
for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1) {
for (let g of item.key) {
if (datas[g] && item.filterEmpty && item.filterEmpty.includes(g)) {
// 压缩代码功能暂时屏蔽
/***
// console.log(datas[g]);
// console.log('%c加密数据压缩前字段' + g + '= ', 'color: red;');
// console.log('%c'+ datas[g] , 'color: red;');
// datas[g] = datas[g].replace(/\r/g, ' ').replace(/\t/g, ' ').replace(/\n/g, ' ').replace(/\s\s+/g, ' ');
// console.log('%c加密数据压缩后字段' + g + '= ', 'color: orange;');
// console.log('%c'+ datas[g] , 'color: orange;');
***/
}
if (g === 'allValues' && typeof datas[g] !== 'undefined') {
datas = await countAllValues(datas, item); // 循环中 不要写await
datas = giveKey('allValues', datas);
} else {
// console.log(g, datas);
datas = giveKey(g, datas);
}
}
if (item.yinShe) {
// 映射参数字段.
datas.isBase = true;
for (let oldKey in item.yinShe) {
let newKey = item.yinShe[oldKey];
// if(typeof datas[oldKey] !== 'undefined'){
datas[newKey] = datas[oldKey];
delete datas[oldKey];
// }
}
}
return datas;
}
}
}
return datas;
}
import encryptApiList, { resBinaryApiList } from '@/webPublic/one_stop_public/Base16/encryptApiList';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import { queryApiActionPath } from '@/webPublic/one_stop_public/utils/queryConfig';
import { qqCw } from '@/webPublic/one_stop_public/utils/request';
import { isJSON } from '@/webPublic/zyd_public/utils/utils';
import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils';
import strToBinary from './strToBinary';
/**
* 字符串转二进制 增加代码混淆
* */
// function strToBinary(str) {
// let result = [];
// let list = str.split('');
// for (let i = 0; i < list.length; i++) {
// if (i !== 0) {
// result.push('_');
// }
// let item = list[i];
// let binaryStr = item.charCodeAt()
// .toString(2);
// result.push(binaryStr);
// }
// let resultStr = result.join('');
// resultStr = resultStr.replaceAll('0', '-').replaceAll('1', '.');
// return resultStr;
// }
/**
* 二进制字符串转JSON字符串
* */
function binaryToStr(binaryStr = '') {
let res = '';
if (binaryStr) {
binaryStr = binaryStr.replaceAll('.', '1');
binaryStr = binaryStr.replaceAll('-', '0');
let strListArr = binaryStr.split('_');
for (let i = 0; i < strListArr.length; i++) {
let item = strListArr[i];
res += String.fromCharCode(parseInt(item, 2));
}
}
return res;
}
function formatDatas(datas, url = '') {
let datasCode = JSON.stringify(datas);
const openIsBinary = window.CONFIG?.IS_BINARY;
if (openIsBinary) {
datasCode = strToBinary(datasCode);
}
let file = new File([datasCode], 'fileParams.jpeg', {
type: 'image/jpeg',
});
let datasTrue = {
fileParams: file,
};
if (openIsBinary) {
datasTrue.bin = true;
if(window.CONFIG?.ALLBIN){
datasTrue.rbin = true;
}else{
let findIndexA = resBinaryApiList.findIndex(g => {
return url.includes(g.api);
});
if (findIndexA >= 0) {
datasTrue.rbin = true;
}
}
}
return datasTrue;
}
export function giveFilePostData(datas, url) {
for (let i in datas) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
if (url && typeof url === 'string') {
for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1 || Window.CONFIG?.ALLBIN) {
const roleGroup = getUserInfo().groupsId;
if (url.indexOf('http') > -1) {
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`);
} else {
url = url.replace(url, `/safe/${roleGroup}/` + url);
url = url.replaceAll('//', '/');
}
return new Promise((resolve, reject) => {
resolve({
datas: formatDatas(datas, url),
url,
});
});
}
}
}
return new Promise((resolve, reject) => {
resolve(datas);
return datas;
});
}
export function requestFileInfo(url, datas) {
const formData = new FormData();
if (getToken()) {
datas.token = getToken();
}
for (let key in datas) {
formData.append(key, datas[key]);
}
if (!url || typeof url !== 'string') {
console.log(url);
return false;
}
return fetch(url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url, {
headers: {
Accept: 'application/json',
// Authorization: `bearer ${getToken()}`,
},
method: 'POST',
credentials: 'omit',
mode: 'cors',
body: formData,
})
.then(res => {
if (res.status === 401) {
qqCw({
title: '登录过期401',
customErrMsg: '登录已过期,请重新登录',
});
return false;
}
if (res.status === 404) {
qqCw({
title: 'http404报错',
customErrMsg: '请联系系统管理员',
});
return false;
}
// console.log(res.status);
return res.json();
})
.then(res => {
if (res && typeof res === 'object' && res.rbin) {
res = binaryToStr(res.rbin);
if (isJSON(res)) {
res = JSON.parse(res);
}
// console.log(res);
}
if (res && res.errCode) {
qqCw({
msg: res.errMsg || res.message,
customErrMsg: res.customErrMsg,
});
return false;
}
if(window.location.origin.indexOf('localhost') > -1){
console.log({
datas,
url,
res,
});
}
return res;
});
}
export function giveFilePostDataInfoForTrue(datas, url) {
if (!window.CONFIG?.IS_SAFE) {
return {
datas,
url,
};
}
datas = deepCopy(datas);
for (let i in datas) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
if (url) {
const roleGroup = getUserInfo().groupsId;
if (url.indexOf('http') > -1) {
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`);
} else {
url = url.replace(url, `/safe/${roleGroup}/` + url);
url = url.replaceAll('//', '/');
}
return {
datas: formatDatas(datas, url),
url,
};
}
}
import baseX from 'base-x';
import { apiRequest, qqCw } from '../utils/request';
import { isJSON } from '@/webPublic/zyd_public/utils/utils';
import {
queryApiActionPath,
queryIsBinary,
queryIsSafe,
} from '@/webPublic/one_stop_public/utils/queryConfig';
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
import encryptApiList, { resBinaryApiList } from './encryptApiList';
import { queryIsSafe } from '@/webPublic/one_stop_public/utils/queryConfig';
import { uploadFile } from '@/webPublic/one_stop_public/libs/PictureSignature/ShowItem';
import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils';
var BASE16 = '0123456789abcdef';
var bs16 = baseX(BASE16);
function checkOpenBase16() {
const is_open_base14 = sessionStorage.getItem('is_open_base16')
? JSON.parse(sessionStorage.getItem('is_open_base16'))
: false;
return is_open_base14;
}
export function Base16Encode(value) {
const is_open_base14 = checkOpenBase16();
if (is_open_base14) {
if (!value) {
return null;
} else {
let newV = new Buffer(value); // 快
const r = bs16.encode(newV); // 慢
return r;
}
}
return value;
}
const giveKey = (key, datas) => {
if (datas && datas[key]) {
datas[key] = Base16Encode(datas[key]);
}
return datas;
};
const countAllValues = async (datas, item) => {
if (item.setNull) {
datas.allValues = JSON.stringify({});
} else {
if (item.query) {
if (datas?.sqlKey.length < 13) {
const response = await apiRequest('/SqlManageEntityApi/findParamsKey', {
sqlKey: datas.sqlKey,
});
if (!response || (Array.isArray(response) && response.length === 0)) {
datas.allValues = JSON.stringify({});
} else {
const x = (isJSON(datas.allValues) && JSON.parse(datas.allValues)) || {};
const y = {};
for (let i of response) {
if (x[i]) {
y[i] = x[i];
}
datas.allValues = JSON.stringify(y);
}
}
} else {
datas.allValues = JSON.stringify({});
}
}
}
return datas;
};
export function requestFileInfo(url, datas) {
const formData = new FormData();
if (getToken()) {
datas.token = getToken();
}
for (let key in datas) {
formData.append(key, datas[key]);
}
if (!url || typeof url !== 'string') {
console.log(url);
return false;
}
return fetch(url && url.indexOf('http') > -1 ? url : queryApiActionPath() + url, {
headers: {
Accept: 'application/json',
// Authorization: `bearer ${getToken()}`,
},
method: 'POST',
credentials: 'omit',
mode: 'cors',
body: formData,
})
.then(res => {
if (res.status === 401) {
qqCw({
title: '登录过期401',
customErrMsg: '登录已过期,请重新登录',
});
return false;
}
if (res.status === 404) {
qqCw({
title: 'http404报错',
customErrMsg: '请联系系统管理员',
});
return false;
}
// console.log(res.status);
return res.json();
})
.then(res => {
if (res && typeof res === 'object' && res.rbin) {
res = binaryToStr(res.rbin);
if (isJSON(res)) {
res = JSON.parse(res);
}
// console.log(res);
}
if (res && res.errCode) {
qqCw({
msg: res.errMsg || res.message,
customErrMsg: res.customErrMsg,
});
return false;
}
if(window.location.origin.indexOf('localhost') > -1){
console.log({
datas,
url,
res,
});
}
return res;
});
}
function formatDatas(datas, url = '') {
let datasCode = JSON.stringify(datas);
const openIsBinary = window.CONFIG?.IS_BINARY;
if (openIsBinary) {
datasCode = strToBinary(datasCode);
}
let file = new File([datasCode], 'fileParams.jpeg', {
type: 'image/jpeg',
});
let datasTrue = {
fileParams: file,
};
if (openIsBinary) {
datasTrue.bin = true;
if(window.CONFIG?.ALLBIN){
datasTrue.rbin = true;
}else{
let findIndexA = resBinaryApiList.findIndex(g => {
return url.includes(g.api);
});
if (findIndexA >= 0) {
datasTrue.rbin = true;
}
}
}
return datasTrue;
}
export function giveFilePostDataInfoForTrue(datas, url) {
if (!window.CONFIG?.IS_SAFE) {
return {
datas,
url,
};
}
datas = deepCopy(datas);
for (let i in datas) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
if (url) {
const roleGroup = getUserInfo().groupsId;
if (url.indexOf('http') > -1) {
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`);
} else {
url = url.replace(url, `/safe/${roleGroup}/` + url);
url = url.replaceAll('//', '/');
}
return {
datas: formatDatas(datas, url),
url,
};
}
}
/**
* 字符串转二进制
* */
function strToBinary(str) {
let result = [];
let list = str.split('');
for (let i = 0; i < list.length; i++) {
if (i !== 0) {
result.push('_');
}
let item = list[i];
let binaryStr = item.charCodeAt()
.toString(2);
result.push(binaryStr);
}
let resultStr = result.join('');
resultStr = resultStr.replaceAll('0', '-').replaceAll('1', '.');
return resultStr;
}
/**
* 二进制字符串转JSON字符串
* */
function binaryToStr(binaryStr = '') {
let res = '';
if (binaryStr) {
binaryStr = binaryStr.replaceAll('.', '1');
binaryStr = binaryStr.replaceAll('-', '0');
let strListArr = binaryStr.split('_');
import {
Base16Encode,
giveBase16EncodeAsync,
} from './SplitBase16Index';
import { giveFilePostData, giveFilePostDataInfoForTrue, requestFileInfo } from './binaryEncode';
for (let i = 0; i < strListArr.length; i++) {
let item = strListArr[i];
res += String.fromCharCode(parseInt(item, 2));
}
}
return res;
}
function giveFilePostData(datas, url) {
for (let i in datas) {
if (
datas[i] === null ||
(Array.isArray(datas[i]) && datas[i].length === 0) ||
datas[i] === undefined
) {
delete datas[i];
}
}
if (url && typeof url === 'string') {
for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1 || Window.CONFIG?.ALLBIN) {
const roleGroup = getUserInfo().groupsId;
if (url.indexOf('http') > -1) {
url = url.replace('/onestop/', `/onestop/safe/${roleGroup}/`);
} else {
url = url.replace(url, `/safe/${roleGroup}/` + url);
url = url.replaceAll('//', '/');
}
return new Promise((resolve, reject) => {
resolve({
datas: formatDatas(datas, url),
url,
});
});
}
}
}
return new Promise((resolve, reject) => {
resolve(datas);
return datas;
});
}
export { Base16Encode, requestFileInfo, giveFilePostDataInfoForTrue };
export async function giveBase16EnCode(datas, url) {
// 全局加解密函数.
if (queryIsSafe()) {
return giveFilePostData(datas, url);
}
if (!checkOpenBase16()) {
return datas;
}
if (url && typeof url === 'string') {
for (let item of encryptApiList) {
if (url.indexOf(item.api) > -1) {
for (let g of item.key) {
if (datas[g] && item.filterEmpty && item.filterEmpty.includes(g)) {
// 压缩代码功能暂时屏蔽
/***
// console.log(datas[g]);
// console.log('%c加密数据压缩前字段' + g + '= ', 'color: red;');
// console.log('%c'+ datas[g] , 'color: red;');
// datas[g] = datas[g].replace(/\r/g, ' ').replace(/\t/g, ' ').replace(/\n/g, ' ').replace(/\s\s+/g, ' ');
// console.log('%c加密数据压缩后字段' + g + '= ', 'color: orange;');
// console.log('%c'+ datas[g] , 'color: orange;');
***/
}
if (g === 'allValues' && typeof datas[g] !== 'undefined') {
datas = await countAllValues(datas, item); // 循环中 不要写await
datas = giveKey('allValues', datas);
} else {
// console.log(g, datas);
datas = giveKey(g, datas);
}
}
if (item.yinShe) {
// 映射参数字段.
datas.isBase = true;
for (let oldKey in item.yinShe) {
let newKey = item.yinShe[oldKey];
// if(typeof datas[oldKey] !== 'undefined'){
datas[newKey] = datas[oldKey];
delete datas[oldKey];
// }
}
}
return datas;
}
}
}
return datas;
return giveBase16EncodeAsync(datas, url);
}
function _0x4ef8() {
const _0x17bb5a = ['481374jxbvau', 'push', '28wsNjbv', '5xIHGnt', 'charCodeAt', '1024904tHoNdW', '11191763OpoFLZ', '624243CCgrxw', '2isqBwU', '1394360vTUesG', '387gETRxx', '96020VVIGLY', '367205YUbBcj'];
_0x4ef8 = function () {
return _0x17bb5a;
};
return _0x4ef8();
}
function _0x251b(_0x3e6559, _0x18d143) {
const _0x4ef8c2 = _0x4ef8();
return _0x251b = function (_0x251bf7, _0x3cfc29) {
_0x251bf7 = _0x251bf7 - 0x10f;
let _0x450bfc = _0x4ef8c2[_0x251bf7];
return _0x450bfc;
}, _0x251b(_0x3e6559, _0x18d143);
}
(function (_0xca7f49, _0x4d2eee) {
const _0x1de042 = _0x251b,
_0x4adbdc = _0xca7f49();
while (!![]) {
try {
const _0x553796 = parseInt(_0x1de042(0x11b)) / 0x1 + parseInt(_0x1de042(0x117)) / 0x2 * (parseInt(_0x1de042(0x116)) / 0x3) + -parseInt(_0x1de042(0x114)) / 0x4 * (parseInt(_0x1de042(0x112)) / 0x5) + parseInt(_0x1de042(0x10f)) / 0x6 * (parseInt(_0x1de042(0x111)) / 0x7) + parseInt(_0x1de042(0x118)) / 0x8 + parseInt(_0x1de042(0x119)) / 0x9 * (parseInt(_0x1de042(0x11a)) / 0xa) + -parseInt(_0x1de042(0x115)) / 0xb;
if (_0x553796 === _0x4d2eee) break; else _0x4adbdc['push'](_0x4adbdc['shift']());
} catch (_0x44d7aa) {
_0x4adbdc['push'](_0x4adbdc['shift']());
}
}
}(_0x4ef8, 0x3333c));
function strToBinary(_0x18b19e) {
const _0x34cebd = _0x251b;
let _0x54a5d7 = [],
_0x4f6eaa = _0x18b19e['split']('');
for (let _0x2bcf5e = 0x0; _0x2bcf5e < _0x4f6eaa['length']; _0x2bcf5e++) {
_0x2bcf5e !== 0x0 && _0x54a5d7[_0x34cebd(0x110)]('_');
let _0x435a20 = _0x4f6eaa[_0x2bcf5e],
_0x1d8e9b = _0x435a20[_0x34cebd(0x113)]()['toString'](0x2);
_0x54a5d7[_0x34cebd(0x110)](_0x1d8e9b);
}
let _0x3be325 = _0x54a5d7['join']('');
return _0x3be325 = _0x3be325['replaceAll']('0', '-')['replaceAll']('1', '.'), _0x3be325;
}
export default strToBinary;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论