From ff36d048b287f6d9c3f655c9cdd1394c95553894 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Tue, 7 Jan 2025 09:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E5=8E=BB=E9=99=A4=E5=8A=A0?= =?UTF-8?q?=E5=AF=86=E8=A7=A3=E5=AF=86=E6=96=B9=E6=B3=95=EF=BC=8C=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=88=B0app=E4=BC=9A=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/encryptUtil.js | 65 ++------------------------------------------ 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/utils/encryptUtil.js b/utils/encryptUtil.js index c1b1f31..5023b89 100644 --- a/utils/encryptUtil.js +++ b/utils/encryptUtil.js @@ -1,64 +1,3 @@ -import { SM4 } from 'gm-crypto' -import {encryptKey} from '@/commons/config.js' - -let HEX_KEY = null - -// 字符串转16进制 -function str2hex(str) { - var val = '' - for (var i = 0; i < str.length; i++) { - if (val == '') - val = str.charCodeAt(i).toString(16) - else - val += str.charCodeAt(i).toString(16) - } - val += '' - return val -} - -// 获取hex秘钥 -function getHexKey(){ - - if(!HEX_KEY){ - - HEX_KEY = str2hex(encryptKey) - - } - return HEX_KEY -} - - -// 解密 (http响应数据, 做通用处理) export function sm4DecryptByResData(data){ - - if(!data){ - return data - } - - let res = SM4.decrypt(data, getHexKey(), { - inputEncoding: 'base64', - outputEncoding: 'utf8' - }) - - if(!res){ - return res - } - - return JSON.parse(res)['originData'] -} - -// 加密 (http响应数据, 做通用处理) -export function sm4EncryptByReqData(data){ - if(!data){ - return data - } - - // 加密处理 - let encryptData = SM4.encrypt(JSON.stringify(data), getHexKey(), { - inputEncoding: 'utf8', - outputEncoding: 'base64' - }) - - return {encryptData : encryptData} -} - + return data +} \ No newline at end of file