Files
LSM_OIL_SITE/utils/encode.js
xk_guohonglei 1f8b3e6e55 首次提交
2020-08-18 15:09:31 +08:00

31 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import CryptoJS from 'crypto-js'
import md5 from 'js-md5'
let Base64 = require('js-base64').Base64
var keyStr = 'qDfajQ*v@W1mCruZ'
export default {
/**
* @param {*需要加密的字符串 注对象转化为json字符串再加密} word
* @param {*aes加密需要的key值这个key值后端同学会告诉你} keyStr
*/
encrypt (word) { // 加密
var key = CryptoJS.enc.Utf8.parse(keyStr)
var srcs = CryptoJS.enc.Utf8.parse(word)
var encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }) // 加密模式为ECB补码方式为PKCS5Padding也就是PKCS7
return encrypted.toString()
},
decrypt (word) { // 解密
var key = CryptoJS.enc.Utf8.parse(keyStr)
var decrypt = CryptoJS.AES.decrypt(word, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 })
return CryptoJS.enc.Utf8.stringify(decrypt).toString()
},
md5Salt (str) {
return Base64.encode(md5(str + 'Do&9hY%l8e'))
},
md5NoSalt (str) {
return md5(str)
}
}