v3.9.0【优化】typescript版本;【优化】App端消息;【优化】弹出层z-index;

This commit is contained in:
zhuoda
2024-11-04 20:15:49 +08:00
parent 17a3e1fd86
commit 69fa9088f5
1376 changed files with 10373 additions and 9712 deletions

View File

@@ -2,7 +2,7 @@ import CryptoJS from 'crypto-js';
import CryptoSM from 'sm-crypto';
function object2string(data) {
if (typeof data === 'Object') {
if (typeof data === 'object') {
return JSON.stringify(data);
}
@@ -16,8 +16,29 @@ function object2string(data) {
return str;
}
// ----------------------- AES 加密、解密 -----------------------
const AES_KEY = '1024abcd1024abcd1024abcd1024abcd';
/**
* 字符串转为数字
*/
function stringToHex(str) {
let hex = '';
for(let i = 0; i < str.length; i++) {
hex += str.charCodeAt(i).toString(16).padStart(2, '0');
}
return hex;
}
/*
* -------------------- ※ AES 加密、解密 begin ※ --------------------
*
* 1、AES加密算法支持三种密钥长度128位、192位和256位这里选择128位
* 2、AES 要求秘钥为 128bit转化字节为 16个字节
* 3、js前端使用 UCS-2 或者 UTF-16 编码,字母、数字、特殊符号等 占用1个字节
* 4、所以秘钥Key 组成为:字母、数字、特殊符号 一共16个即可
*
* -------------------- ※ AES 加密、解密 end ※ --------------------
*/
const AES_KEY = '1024lab__1024lab';
const AES = {
encryptData: function (data) {
@@ -28,8 +49,7 @@ const AES = {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
});
return encrypted.toString();
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
},
decryptData: function (data) {
@@ -45,13 +65,24 @@ const AES = {
},
};
// ----------------------- 国密SM4算法 加密、解密 -----------------------
const SM4_KEY = '1024abcd1024abcd1024abcd1024abcd';
/*
* -------------------- ※ 国密SM4算法 加密、解密 begin ※ --------------------
*
* 1、国密SM4 要求秘钥为 128bit转化字节为 16个字节
* 2、js前端使用 UCS-2 或者 UTF-16 编码,字母、数字、特殊符号等 占用1个字节
* 3、java中 每个 字母数字 也是占用1个字节
* 4、所以前端和后端的 秘钥Key 组成为:字母、数字、特殊符号 一共16个即可
*
* -------------------- ※ 国密SM4算法 加密、解密 end ※ --------------------
*/
// 秘钥Key 组成为:字母、数字、特殊符号 一共16个即可
const SM4_KEY = '1024lab__1024lab';
const SM4 = {
encryptData: function (data) {
// 第一步SM4 加密
let encryptData = CryptoSM.sm4.encrypt(object2string(data), SM4_KEY);
let encryptData = CryptoSM.sm4.encrypt(object2string(data), stringToHex(SM4_KEY));
// 第二步: Base64 编码
return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(encryptData));
},
@@ -62,10 +93,12 @@ const SM4 = {
let decode64Str = CryptoJS.enc.Utf8.stringify(words);
// 第二步SM4 解密
return CryptoSM.sm4.decrypt(decode64Str, SM4_KEY);
return CryptoSM.sm4.decrypt(decode64Str, stringToHex(SM4_KEY));
},
};
// ----------------------- 对外暴露: 加密、解密 -----------------------
// 默认使用SM4算法