mirror of
http://112.124.100.131/GFRS/ebiz-h5.git
synced 2025-12-12 10:16:43 +08:00
前端缓存加密AES
This commit is contained in:
@@ -25,6 +25,8 @@
|
||||
"echarts": "^4.2.1",
|
||||
"fastclick": "^1.0.6",
|
||||
"js-base64": "^2.5.1",
|
||||
"crypto-js": "^4.0.0",
|
||||
"js-md5": "^0.7.3",
|
||||
"nprogress": "^0.2.0",
|
||||
"pdfh5": "^1.2.13",
|
||||
"vant": "2.2.0",
|
||||
|
||||
59
src/assets/js/utils/cacheUtils.js
Normal file
59
src/assets/js/utils/cacheUtils.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import AESTools from '@/assets/js/utils/cryptoJsUtil'
|
||||
import configApp from '@/config'
|
||||
import cacheKeys from '@/assets/js/utils/needCacheKey'
|
||||
export default {
|
||||
setLocItem: function(key, value) {
|
||||
const exist = cacheKeys.encodeKeys.find(item => {
|
||||
return item === key
|
||||
})
|
||||
//设置localStorage 值
|
||||
if (cacheKeys.isAll || exist) {
|
||||
window.localStorage.setItem(key, AESTools.AESCacheEncrypt(value, configApp.CACHE_ENCRYP))
|
||||
} else {
|
||||
window.localStorage.setItem(key, value)
|
||||
}
|
||||
},
|
||||
getLocItem: function(key) {
|
||||
// 获取localStorage 中值
|
||||
let value = window.localStorage.getItem(key)
|
||||
if (value && value != '') {
|
||||
const exist = cacheKeys.encodeKeys.find(item => {
|
||||
return item === key
|
||||
})
|
||||
if (cacheKeys.isAll || exist) {
|
||||
return AESTools.AESCacheDecrypt(value, configApp.CACHE_ENCRYP)
|
||||
}
|
||||
}
|
||||
return value
|
||||
},
|
||||
removeLocItem: function(key) {
|
||||
// 获取localStorage 中值
|
||||
window.localStorage.removeItem(key)
|
||||
},
|
||||
setSessionItem: function(key, value) {
|
||||
//设置sessionStorage 值
|
||||
const exist = cacheKeys.encodeKeys.find(item => {
|
||||
return item === key
|
||||
})
|
||||
//设置localStorage 值
|
||||
if (cacheKeys.isAll || exist) {
|
||||
window.sessionStorage.setItem(key, AESTools.AESCacheEncrypt(value, configApp.CACHE_ENCRYP))
|
||||
} else {
|
||||
window.sessionStorage.setItem(key, value)
|
||||
}
|
||||
},
|
||||
getSessionItem: function(key) {
|
||||
//设置sessionStorage 值
|
||||
let value = window.sessionStorage.getItem(key)
|
||||
if (value && value != '') {
|
||||
const exist = cacheKeys.encodeKeys.find(item => {
|
||||
return item === key
|
||||
})
|
||||
//设置localStorage 值
|
||||
if (cacheKeys.isAll || exist) {
|
||||
return AESTools.AESCacheDecrypt(value, configApp.CACHE_ENCRYP)
|
||||
}
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
47
src/assets/js/utils/cryptoJsUtil.js
Normal file
47
src/assets/js/utils/cryptoJsUtil.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import CryptoJS from 'crypto-js'
|
||||
export default {
|
||||
AESEncrypt: function(data, keys) {
|
||||
//加密
|
||||
var key = CryptoJS.enc.Hex.parse(keys)
|
||||
var iv = CryptoJS.enc.Utf8.parse('0123456789ABCDEF') //偏移量
|
||||
var encrypted = CryptoJS.AES.encrypt(data, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return encrypted.toString()
|
||||
},
|
||||
AESDecrypt: function(encrypted, keys) {
|
||||
//解密
|
||||
var key = CryptoJS.enc.Hex.parse(keys)
|
||||
var iv = CryptoJS.enc.Utf8.parse('0123456789ABCDEF')
|
||||
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return CryptoJS.enc.Utf8.stringify(decrypted)
|
||||
},
|
||||
AESCacheEncrypt: function(data, keys) {
|
||||
//加密 緩存
|
||||
var key = CryptoJS.enc.Hex.parse(keys)
|
||||
var iv = CryptoJS.enc.Utf8.parse('0123456789ABCDEF') //偏移量
|
||||
var encrypted = CryptoJS.AES.encrypt(data, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return encrypted.toString()
|
||||
},
|
||||
AESCacheDecrypt: function(encrypted, keys) {
|
||||
//解密 緩存
|
||||
var key = CryptoJS.enc.Hex.parse(keys)
|
||||
var iv = CryptoJS.enc.Utf8.parse('0123456789ABCDEF')
|
||||
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
})
|
||||
return CryptoJS.enc.Utf8.stringify(decrypted)
|
||||
}
|
||||
}
|
||||
4
src/assets/js/utils/needCacheKey.js
Normal file
4
src/assets/js/utils/needCacheKey.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
isAll: false,
|
||||
encodeKeys: ['saleInsuredInfo', 'saleInsuredPersonInfo', 'appntDTO', 'proposalAppnt']
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
let apiDomain, imgDomain, assetsUrl, mainUrl, payUrl, zssqUrl // 保融支付的收银台服务地址
|
||||
let apiDomain, imgDomain, assetsUrl, mainUrl, payUrl, zssqUrl, REQ_PWD, CACHE_ENCRYP, API_VERSION // 保融支付的收银台服务地址
|
||||
|
||||
// 可以多个接口域名,按需添加
|
||||
console.log('环境:', process.env.VUE_APP_FLAG)
|
||||
@@ -18,6 +18,9 @@ switch (process.env.VUE_APP_FLAG) {
|
||||
mainUrl = 'http://139.199.50.151'
|
||||
payUrl = 'https://funduat.e-guofu.com/s3-modules-gateway/embed/gateway.action'
|
||||
zssqUrl = 'http://139.199.50.151/html/test/index.html#/'
|
||||
REQ_PWD = '41424344454631323334353637383930'
|
||||
CACHE_ENCRYP = '41424344454631323334353637383930'
|
||||
API_VERSION = 'v2'
|
||||
break
|
||||
case 'uat':
|
||||
apiDomain = 'http://115.159.235.59:7000/api/v1' // 国富api
|
||||
@@ -27,6 +30,9 @@ switch (process.env.VUE_APP_FLAG) {
|
||||
mainUrl = 'http://115.159.235.59'
|
||||
payUrl = 'https://funduat.e-guofu.com/s3-modules-gateway/embed/gateway.action'
|
||||
zssqUrl = ''
|
||||
REQ_PWD = '41424344454631323334353637383930'
|
||||
CACHE_ENCRYP = '41424344454631323334353637383930'
|
||||
API_VERSION = 'v2'
|
||||
break
|
||||
case 'prd':
|
||||
apiDomain = 'https://iagentsales.e-guofu.com/api/v1'
|
||||
@@ -35,6 +41,9 @@ switch (process.env.VUE_APP_FLAG) {
|
||||
mainUrl = 'https://iagentsales.e-guofu.com'
|
||||
payUrl = 'https://uns3.e-guofu.com/s3-modules-gateway/embed/gateway.action'
|
||||
zssqUrl = ''
|
||||
REQ_PWD = '41424344454631323334353637383930'
|
||||
CACHE_ENCRYP = '41424344454631323334353637383930'
|
||||
API_VERSION = 'v2'
|
||||
break
|
||||
case 'dat':
|
||||
apiDomain = ''
|
||||
@@ -44,6 +53,9 @@ switch (process.env.VUE_APP_FLAG) {
|
||||
mainUrl = ''
|
||||
payUrl = ''
|
||||
zssqUrl = ''
|
||||
REQ_PWD = '41424344454631323334353637383930'
|
||||
CACHE_ENCRYP = '41424344454631323334353637383930'
|
||||
API_VERSION = 'v2'
|
||||
break
|
||||
}
|
||||
/**
|
||||
@@ -61,5 +73,8 @@ export default {
|
||||
assetsUrl,
|
||||
mainUrl,
|
||||
payUrl,
|
||||
zssqUrl //知识社区地址
|
||||
zssqUrl, //知识社区地址
|
||||
REQ_PWD, //报文加密密码
|
||||
CACHE_ENCRYP, //缓存加密密码
|
||||
API_VERSION //渠道版本
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import config from '@/config'
|
||||
import noMoreClick from '@/directive/noMoreClick'
|
||||
import vueHashCalendar from 'vue-hash-calendar'
|
||||
import 'vue-hash-calendar/lib/vue-hash-calendar.css'
|
||||
import md5 from 'js-md5'
|
||||
import cryptoJs from 'crypto-js'
|
||||
import cacheUtils from '@/assets/js/utils/cacheUtils'
|
||||
|
||||
import { Cell, CellGroup, DatetimePicker, Popup, Picker, Col, Row, Tab, Tabs, NavBar, Toast, Button, Dialog, Icon, Lazyload } from 'vant'
|
||||
Vue.use(Cell)
|
||||
@@ -35,6 +38,9 @@ Vue.use(Lazyload, {
|
||||
Vue.prototype.$assetsUrl = config.assetsUrl
|
||||
Vue.prototype.$mainUrl = config.mainUrl
|
||||
Vue.prototype.$zssqUrl = config.zssqUrl
|
||||
Vue.prototype.$MD5 = md5
|
||||
Vue.prototype.$CryptoJs = cryptoJs
|
||||
Vue.prototype.$CacheUtils = cacheUtils
|
||||
|
||||
// 全局 防重复点击
|
||||
Vue.directive('no-more-click', noMoreClick)
|
||||
|
||||
Reference in New Issue
Block a user