feat: 登录强制校验弱密码&关键信息加密传输

This commit is contained in:
meilin.huang
2022-07-18 20:36:31 +08:00
parent db554ebdc9
commit 5271bd21e8
29 changed files with 1804 additions and 1327 deletions

View File

@@ -0,0 +1,37 @@
import openApi from './openApi';
import JSEncrypt from 'jsencrypt'
import { notBlank } from './assert';
var encryptor: any = null
export async function getRsaPublicKey() {
let publicKey = sessionStorage.getItem('RsaPublicKey')
if (publicKey) {
return publicKey
}
publicKey = await openApi.getPublicKey() as string
sessionStorage.setItem('RsaPublicKey', publicKey)
return publicKey
}
/**
* 公钥加密指定值
*
* @param value value
* @returns 加密后的值
*/
export async function RsaEncrypt(value: any) {
// 不存在则返回空值
if (!value) {
return ""
}
if (encryptor != null) {
return encryptor.encrypt(value)
}
console.log(value)
encryptor = new JSEncrypt()
const publicKey = await getRsaPublicKey() as string;
notBlank(publicKey, "获取公钥失败")
encryptor.setPublicKey(publicKey)//设置公钥
return encryptor.encrypt(value)
}