🔨 加密参数.
This commit is contained in:
22
orion-visor-ui/src/utils/rsa.ts
Normal file
22
orion-visor-ui/src/utils/rsa.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user