🔨 加密参数.

This commit is contained in:
lijiahang
2025-01-13 15:48:33 +08:00
parent c481cb0ae4
commit f65aa89421
17 changed files with 138 additions and 44 deletions

View File

@@ -0,0 +1,22 @@
import { JSEncrypt } from 'jsencrypt';
import { useCacheStore } from '@/store';
import { Message } from '@arco-design/web-vue';
// 加密
export const encrypt = async (data: string | undefined): Promise<string | undefined> => {
// 为空直接返回
if (!data) {
return data;
}
// 获取公钥
const { encrypt } = await useCacheStore().loadSystemSetting();
const encryptor = new JSEncrypt();
encryptor.setPublicKey(encrypt?.publicKey);
// 加密
const value = encryptor.encrypt(data);
if (value === false) {
Message.error('数据加密失败');
throw new Error('数据加密失败');
}
return value;
};