mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-13 12:56:49 +08:00
sm2-加密
This commit is contained in:
@@ -8,8 +8,7 @@ import { logger } from 'runjs/lib/common'
|
||||
import {
|
||||
decryptWithPrivateKey,
|
||||
encrypt,
|
||||
shouldEncrypt,
|
||||
privateKeyHex
|
||||
shouldEncrypt
|
||||
} from '@/assets/js/utils/encrypt'
|
||||
|
||||
// create an axios instance
|
||||
@@ -57,12 +56,13 @@ service.interceptors.request.use(
|
||||
return true
|
||||
}
|
||||
|
||||
// 跳过自定义标记不加密的请求
|
||||
return !shouldEncrypt(config)
|
||||
// // 跳过自定义标记不加密的请求 (在encrypt.js中已写这部分逻辑)
|
||||
const url = config.url.substring(config.url.lastIndexOf(':')).substring(6)
|
||||
return !shouldEncrypt(url)
|
||||
}
|
||||
|
||||
// 4. 执行加密逻辑
|
||||
if (!shouldSkipEncryption() && shouldEncrypt(config)) {
|
||||
if (!shouldSkipEncryption()) {
|
||||
// 添加加密标识(便于调试)
|
||||
config.headers['X-Encrypted'] = 'true'
|
||||
|
||||
@@ -92,12 +92,14 @@ service.interceptors.response.use(
|
||||
// 解密处理 todo 用config.headers['X-Encrypted'] === 'true'判断是否需要解密不一定准确
|
||||
if (response.config.headers['X-Encrypted'] === 'true') {
|
||||
try {
|
||||
res = decryptWithPrivateKey(res, privateKeyHex, 1)
|
||||
res = decryptWithPrivateKey(res)
|
||||
} catch (e) {
|
||||
logger.error('解密响应失败', e)
|
||||
}
|
||||
}
|
||||
res = JSON.parse(res)
|
||||
if (typeof res === 'string') {
|
||||
res = JSON.parse(res)
|
||||
}
|
||||
endLoading()
|
||||
if (response.config.back) {
|
||||
return res
|
||||
|
||||
Reference in New Issue
Block a user