1
This commit is contained in:
@@ -9,7 +9,7 @@ import {verifyUrl} from '/@/utils/toolsValidate';
|
||||
import request from '/@/utils/request';
|
||||
import {useMessage} from '/@/hooks/message';
|
||||
import * as CryptoJS from 'crypto-js';
|
||||
import {sm4} from 'sm-crypto'
|
||||
import { sm4, sm2 } from 'sm-crypto'
|
||||
import {validateNull} from './validate';
|
||||
|
||||
|
||||
@@ -240,6 +240,17 @@ export function sm4Decryption(src: string, keyWord: string) {
|
||||
return sm4.decrypt(src, keyWord);
|
||||
}
|
||||
|
||||
/**
|
||||
* SM2 加密(登录密码等,与后端 SM2 私钥解密配套)
|
||||
* @param msg 明文
|
||||
* @param publicKey 后端提供的 SM2 公钥(十六进制,04 开头 130 字符或 128 字符压缩格式)
|
||||
* @returns 十六进制密文,格式 C1C3C2
|
||||
*/
|
||||
export function sm2Encrypt(msg: string, publicKey: string): string {
|
||||
if (!msg || !publicKey) return msg;
|
||||
return sm2.doEncrypt(msg, publicKey, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base64 加密
|
||||
* @param {*} src 明文
|
||||
@@ -370,6 +381,9 @@ const other = {
|
||||
decryption: (src: string, keyWord: string) => {
|
||||
return decryption(src, keyWord);
|
||||
},
|
||||
sm2Encrypt: (msg: string, publicKey: string) => {
|
||||
return sm2Encrypt(msg, publicKey);
|
||||
},
|
||||
base64Encrypt: (data: any) => {
|
||||
return base64Encrypt(data);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user