|
|
@@ -1,3 +1,5 @@
|
|
|
+import CryptoJS from 'crypto-js'
|
|
|
+
|
|
|
export const formatGetParams = (params) => {
|
|
|
const entries = Object.entries(params).filter(arr => {
|
|
|
return (arr[1] - 0) === 0 || arr[1]
|
|
|
@@ -21,3 +23,52 @@ export const formatGetParams = (params) => {
|
|
|
|
|
|
// return p.join('&')
|
|
|
// }
|
|
|
+
|
|
|
+const desKey = 'fnFACVwC'
|
|
|
+const key = CryptoJS.enc.Hex.parse('TgxRS8DG65EjK8cpKTiPAw==') // 密钥
|
|
|
+const iv = CryptoJS.enc.Hex.parse('') // 偏移量
|
|
|
+
|
|
|
+// aes加密
|
|
|
+export function encrypt (word) {
|
|
|
+ let encrypted = ''
|
|
|
+ if (typeof word === 'string') {
|
|
|
+ const key = CryptoJS.enc.Utf8.parse(desKey)
|
|
|
+ console.log(word, desKey, 'aaaa')
|
|
|
+ encrypted = CryptoJS.DES.encrypt(word, key, {
|
|
|
+ mode: CryptoJS.mode.ECB,
|
|
|
+ padding: CryptoJS.pad.Pkcs7
|
|
|
+ })
|
|
|
+
|
|
|
+ return encrypted.toString()
|
|
|
+
|
|
|
+ // const srcs = CryptoJS.enc.Hex.parse(word)
|
|
|
+ // // var encryptedBase64Str = CryptoJS.enc.Base64.stringify(srcs)
|
|
|
+ // encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
|
|
+ // mode: CryptoJS.mode.ECB,
|
|
|
+ // padding: CryptoJS.pad.ZeroPadding
|
|
|
+ // })
|
|
|
+ } else if (typeof word === 'object') {
|
|
|
+ // 对象格式的转成json字符串
|
|
|
+ const data = JSON.stringify(word)
|
|
|
+ const srcs = CryptoJS.enc.Utf8.parse(data)
|
|
|
+ encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
|
|
+ iv: iv,
|
|
|
+ mode: CryptoJS.mode.ECB,
|
|
|
+ padding: CryptoJS.pad.Pkcs7
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return encrypted.ciphertext.toString()
|
|
|
+}
|
|
|
+
|
|
|
+// aes解密
|
|
|
+export function decrypt (word) {
|
|
|
+ const encryptedHexStr = CryptoJS.enc.Hex.parse(word)
|
|
|
+ const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
|
|
|
+ const decrypt = CryptoJS.AES.decrypt(srcs, key, {
|
|
|
+ iv: iv,
|
|
|
+ mode: CryptoJS.mode.CBC,
|
|
|
+ padding: CryptoJS.pad.Pkcs7
|
|
|
+ })
|
|
|
+ const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
|
|
|
+ return decryptedStr.toString()
|
|
|
+}
|