mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-09 02:46:50 +08:00
sm2-加密(未完成)
This commit is contained in:
2
.env
2
.env
@@ -3,5 +3,5 @@ NODE_ENV = 'dev' // 如果是生产环境,请记得切换为production
|
||||
|
||||
# flag
|
||||
VUE_APP_FLAG='dev'
|
||||
VUE_APP_ADMIN='http://10.1.20.39:7197'
|
||||
VUE_APP_ADMIN='http://10.1.20.39:7537/api'
|
||||
VUE_APP_DOCS='http://39.104.123.254:7546/'
|
||||
|
||||
@@ -810,8 +810,8 @@
|
||||
// 配置模块 - 存储项目配置信息
|
||||
var Config = {
|
||||
ipConfig: {
|
||||
ip: Utils.getQueryParam('ip') || 'http://39.104.123.254:7196'
|
||||
// ip: Utils.getQueryParam('ip') || 'http://10.1.20.39:7197'
|
||||
// ip: Utils.getQueryParam('ip') || 'http://39.104.123.254:7196'
|
||||
ip: Utils.getQueryParam('ip') || 'http://10.1.20.39:7537/api'
|
||||
},
|
||||
|
||||
serviceUrl: {
|
||||
|
||||
@@ -83,10 +83,10 @@ export function encrypt(data, url) {
|
||||
const publicKeyHex = extractSm2RawPublicKey(derPublicKeyHex)
|
||||
|
||||
// 执行加密
|
||||
const ciphertext = sm2.doEncrypt(plaintext, publicKeyHex, {
|
||||
var ciphertext = sm2.doEncrypt(plaintext, publicKeyHex, {
|
||||
cipherMode: 1 // 标准模式
|
||||
})
|
||||
|
||||
ciphertext = '04' + ciphertext
|
||||
console.log('[SM2加密] 明文:', plaintext)
|
||||
console.log('[SM2密钥] 明文:', publicKeyHex)
|
||||
console.log('[SM2加密] 密文:', ciphertext)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import config from '@/config'
|
||||
import urlMap from '@/config/urlMap'
|
||||
export default function getUrl(url, domainType = 'admin') {
|
||||
export default function getUrl(url, domainType = 'jifen') {
|
||||
let domain = ''
|
||||
// if (domainType === 'admin') {
|
||||
// domain = config.admin
|
||||
|
||||
@@ -3,7 +3,7 @@ import { Loading, Message, MessageBox } from 'element-ui'
|
||||
import store from '@/store'
|
||||
import { getToken, removeToken } from '@/assets/js/utils/auth'
|
||||
import router from '@/router'
|
||||
import { sm2 } from 'sm-crypto'
|
||||
import SM, { sm2 } from 'sm-crypto'
|
||||
import { logger } from 'runjs/lib/common'
|
||||
|
||||
import { encrypt } from '@/assets/js/utils/encrypt'
|
||||
@@ -19,7 +19,7 @@ const SM2_PUBLIC_KEY =
|
||||
'3059301306072a8648ce3d020106082a811ccf5501822d0342000463c7ed894e2e4a1c2de4adb8b71c2fa15409356e6851d2f965ddd0e09283044fabb3457bad5a0cbb689d2668309cdb96f987716f0f83125d6f7fa6b295ac0e1f'
|
||||
// SM2私钥
|
||||
const SM2_PRIVATE_KEY =
|
||||
'308193020100301306072a8648ce3d020106082a811ccf5501822d0479307702010104203f5f667ca627d9a442fc5144cbd5ebd81d7fb66158665c7381186c93de4d8edfa00a06082a811ccf5501822da1440342000463c7ed894e2e4a1c2de4adb8b71c2fa15409356e6851d2f965ddd0e09283044fabb3457bad5a0cbb689d2668309cdb96f987716f0f83125d6f7fa6b295ac0e1f'
|
||||
'3f5f667ca627d9a442fc5144cbd5ebd81d7fb66158665c7381186c93de4d8edf'
|
||||
|
||||
// 不加密的URL列表
|
||||
const ENCRYPT_EXCLUDE_URLS = ['/bpic/ta/*']
|
||||
@@ -45,6 +45,8 @@ const encryptData = data => {
|
||||
// 解密函数
|
||||
const decryptData = encrypted => {
|
||||
try {
|
||||
encrypted =
|
||||
'04496dfb4a38707c6ac95416f5dc855c9b5d02a3778ebf6bff18efe9e02fdd132bf65437f3283efeadbf52bec92793e16014b284ea034cdc0e3061fea56ff9495c50af6b0aa8c444ca87976e7ba05fcac47dbda652dad7de54cf0d51f9b6c264eea53fa4f28983f174fb5a702bd8517116340dd77cbb7f385fa02106913a8fa4e61394742a989862c804e43179'
|
||||
const decrypted = sm2.doDecrypt(encrypted, SM2_PRIVATE_KEY, 1)
|
||||
return JSON.parse(decrypted)
|
||||
} catch (e) {
|
||||
@@ -100,8 +102,9 @@ service.interceptors.request.use(
|
||||
// 保存原始数据用于调试
|
||||
config.originalData = config.data
|
||||
// config.data = encryptData(config.data)
|
||||
config.data = encrypt(config.data, config.url)
|
||||
|
||||
var s = { content: encrypt(config.data, config.url) }
|
||||
config.data = JSON.stringify(s)
|
||||
config.headers['Content-Type'] = 'application/json'
|
||||
console.log('config', config)
|
||||
}
|
||||
}
|
||||
@@ -121,7 +124,17 @@ service.interceptors.response.use(
|
||||
response => {
|
||||
endLoading()
|
||||
if (response.config.back) {
|
||||
return response.data
|
||||
let res = response.data
|
||||
// 解密处理
|
||||
if (response.config.headers['X-Encrypted'] === 'true') {
|
||||
try {
|
||||
const contentStr = decryptData(res.content)
|
||||
res.content = contentStr
|
||||
} catch (e) {
|
||||
logger.error('解密响应失败', e)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
// 二进制数据则直接返回
|
||||
if (
|
||||
@@ -130,15 +143,6 @@ service.interceptors.response.use(
|
||||
) {
|
||||
return response.data
|
||||
}
|
||||
let res = response.data
|
||||
// 解密处理
|
||||
if (response.config.headers['X-Encrypted'] === 'true') {
|
||||
try {
|
||||
res = decryptData(res)
|
||||
} catch (e) {
|
||||
logger.error('解密响应失败', e)
|
||||
}
|
||||
}
|
||||
res.code = Number(res.code)
|
||||
if (res.code === 401) {
|
||||
MessageBox.confirm('登录状态已过期,请重新登录', '系统提示', {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
let envInfo = process.env
|
||||
let [admin, jifen, zixi, hz] = [
|
||||
envInfo.VUE_APP_ADMIN,
|
||||
'http://192.168.8.58:7196/',
|
||||
'http://10.48.30.143:7196/',
|
||||
'http://192.168.8.165:7196/',
|
||||
'http://10.147.17.161:7196/'
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user