|
请教各路大侠,js调试过不去,求改写,谢谢
代码如下,主要是const,和data对象不支持
const cryptoKey = '1234567890petecc'
return encryption({
data: {username, password},
key: cryptoKey,
param: ['username', 'password']
})
- function encrypt(username, password) {
- // console.log([username, password])
- const cryptoKey = '1234567890petecc'
- return encryption({
- data: {username, password},
- key: cryptoKey,
- param: ['username', 'password']
- })
- }
- function encryption(params) {
- let {
- data,
- type,
- param,
- key
- } = params
- const result = JSON.parse(JSON.stringify(data))
- if (type === 'Base64') {
- param.forEach(ele => {
- result[ele] = btoa(result[ele])
- })
- } else {
- // console.log(`1@${key}`)
- key = CryptoJS.enc.Latin1.parse(key)
- // console.log(`2@${key}`)
- param.forEach(ele => {
- var data = result[ele]
- var iv = key
- // 加密
- var encrypted = CryptoJS.AES.encrypt(
- data,
- key, {
- iv: iv,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.ZeroPadding
- })
- // encodeURIComponent 特殊字符变成空白符问题
- result[ele] = encodeURIComponent(encrypted.toString())
- })
- }
- return result
- }
复制代码
|
|