2.0.1 • Published 4 months ago
@deephug/encrypt v2.0.1
数据传输加密工具包
切换镜像源
绑定本地 host 文件
10.1.93.111 nexus.wdjky.me
数据包为内网镜像服务
npm config set registry http://nexus.wdjky.me/repository/group-npm/
你可以安装 nrm 管理镜像源
nrm add 863 http://nexus.wdjky.me/repository/group-npm/
nrm use 863
安装
npm install @wonders/encrypt
或者使用 yarn:
yarn add @wonders/encrypt
V1 加密流程
V1 基础使用
客户端加密过程 请求框架为 axios
import { randomStr, aesEncrypt, pan, dora, getUrlParams, parseRes, backdoor, rsaEncrypt } from '@wonders/encrypt';
我们针对源码进行了敏感词混淆,关键词 pan,dora 都进行脱敏,尽量不要直接使用字符串
直接调用包提供的随机串生成方法
const aesKey = randomStr();
const encryptStr = rsaEncrypt(aesKey);
get 请求入参处理
config.headers[pan] = encryptStr;
let urlPanStr = getUrlParams(config.params);
if (urlPanStr) {
config.params = {};
config.params[dora] = aesEncrypt(urlPanStr, aesKey);
}
post 请求入参处理
config.headers[pan] = encryptStr;
if (config.data && JSON.stringify(config.data) != '{}') {
const data = {};
data[dora] = aesEncrypt(JSON.stringify(config.data), aesKey);
config.data = data;
}
开启后门,数据不加密传输,对应的入参也不要加密,否则会有问题
config.headers[backdoor] = true;
解密响应数据
axios(config).then((result) => {
parseRes(result)
})
V2 加密流程
针对 rsa 公钥只加不解原则,以下是升级后的数据加密流程
原先:parseRes(result: AxiosResponse) 变更为:parseRes(result: AxiosResponse, aesKey:string)
解密响应数据
axios(config).then((result) => {
parseRes(result, aesKey) //使用作用域隔离每次请求的aesKey
})
2.0.1
4 months ago