mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-11 11:56:51 +08:00
修复首次登录需要刷新问题
This commit is contained in:
@@ -2,12 +2,6 @@
|
|||||||
import { sm2 } from 'sm-crypto'
|
import { sm2 } from 'sm-crypto'
|
||||||
import { getPrivateKeyHex, getPublicKeyHex } from '@/api/safety'
|
import { getPrivateKeyHex, getPublicKeyHex } from '@/api/safety'
|
||||||
|
|
||||||
// DER 编码的 SM2 公钥(hex)(未解析的公钥)
|
|
||||||
let derPublicKeyHex = sessionStorage.getItem('derPublicKeyHex')
|
|
||||||
|
|
||||||
// 私钥(64位 HEX)(未解析的私钥)
|
|
||||||
let privateKeyHex = sessionStorage.getItem('privateKeyHex')
|
|
||||||
|
|
||||||
// 不加密的URL列表
|
// 不加密的URL列表
|
||||||
const ENCRYPT_EXCLUDE_URLS = ['/bpic/ta/*', '/keyPair/*']
|
const ENCRYPT_EXCLUDE_URLS = ['/bpic/ta/*', '/keyPair/*']
|
||||||
|
|
||||||
@@ -87,7 +81,9 @@ function extractSm2RawPublicKey(derHex) {
|
|||||||
export function encrypt(data) {
|
export function encrypt(data) {
|
||||||
try {
|
try {
|
||||||
const plaintext = typeof data === 'string' ? data : JSON.stringify(data)
|
const plaintext = typeof data === 'string' ? data : JSON.stringify(data)
|
||||||
var publicKeyHex = parseSM2PublicKey(derPublicKeyHex)
|
var publicKeyHex = parseSM2PublicKey(
|
||||||
|
sessionStorage.getItem('derPublicKeyHex')
|
||||||
|
)
|
||||||
publicKeyHex = publicKeyHex.startsWith('04')
|
publicKeyHex = publicKeyHex.startsWith('04')
|
||||||
? publicKeyHex
|
? publicKeyHex
|
||||||
: '04' + publicKeyHex
|
: '04' + publicKeyHex
|
||||||
@@ -115,7 +111,7 @@ export function encrypt(data) {
|
|||||||
*/
|
*/
|
||||||
export function decryptWithPrivateKey(cipherHex) {
|
export function decryptWithPrivateKey(cipherHex) {
|
||||||
try {
|
try {
|
||||||
var privateKey = parseSM2PrivateKey(privateKeyHex)
|
var privateKey = parseSM2PrivateKey(sessionStorage.getItem('privateKeyHex'))
|
||||||
// 校验私钥
|
// 校验私钥
|
||||||
if (!/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
if (!/^[0-9a-fA-F]{64}$/.test(privateKey)) {
|
||||||
throw new Error('系统安全异常,请联系管理员')
|
throw new Error('系统安全异常,请联系管理员')
|
||||||
@@ -149,11 +145,11 @@ export function decryptWithPrivateKey(cipherHex) {
|
|||||||
* 获取原始公钥(用于调试)
|
* 获取原始公钥(用于调试)
|
||||||
*/
|
*/
|
||||||
export function getPublicKey() {
|
export function getPublicKey() {
|
||||||
return derPublicKeyHex
|
return sessionStorage.getItem('derPublicKeyHex')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPrivateKey() {
|
export function getPrivateKey() {
|
||||||
return privateKeyHex
|
return sessionStorage.getItem('privateKeyHex')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 向后端接口获取未解析的公钥
|
// 向后端接口获取未解析的公钥
|
||||||
|
|||||||
Reference in New Issue
Block a user