Browse Source

2024.05.26
- 修改secret文件加密和解密方法;
- 修复首页解码方法调用bug;

zweiqin 10 months ago
parent
commit
83d5774ad1
5 changed files with 30 additions and 16 deletions
  1. 1 2
      config/index.js
  2. 3 3
      package-lock.json
  3. 1 1
      package.json
  4. 22 8
      src/util/secret.js
  5. 3 2
      src/views/home/index.vue

+ 1 - 2
config/index.js

@@ -11,9 +11,8 @@ module.exports = {
     assetsPublicPath: '/',
     proxyTable: {
       '/api': {
-        // target: 'http://192.168.0.150:9007', // 测试
         target: 'https://nsappapi.tuanfengkeji.cn', // 线上
-        // target: 'http://192.168.0.91:9107', // 本地
+        // target: 'https://nsappapitest.tuanfengkeji.cn', // 测试
         changeOrigin: true,
         pathRewrite: {
           '^/api': '/'

+ 3 - 3
package-lock.json

@@ -2524,9 +2524,9 @@
       }
     },
     "crypto-js": {
-      "version": "4.0.0",
-      "resolved": "https://registry.npm.taobao.org/crypto-js/download/crypto-js-4.0.0.tgz",
-      "integrity": "sha1-KQSrJnep0EKFai6i74DekuSjbcw=",
+      "version": "4.1.1",
+      "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz",
+      "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==",
       "dev": true
     },
     "css": {

+ 1 - 1
package.json

@@ -36,7 +36,7 @@
     "babel-preset-stage-2": "^6.22.0",
     "chalk": "^2.0.1",
     "copy-webpack-plugin": "^4.0.1",
-    "crypto-js": "^4.0.0",
+    "crypto-js": "^4.1.1",
     "css-loader": "^0.28.11",
     "es6-promise": "^4.2.5",
     "eslint": "^4.15.0",

+ 22 - 8
src/util/secret.js

@@ -2,17 +2,31 @@ const CryptoJS = require('crypto-js') // 引用AES源码js
 const key = CryptoJS.enc.Utf8.parse('1234125432ABDDFF') // 十六位十六进制数作为密钥
 const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234121134') // 十六位十六进制数作为密钥偏移量
 
+// // 加密方法
+// export function Encrypt (word) {
+//   let srcs = CryptoJS.enc.Utf8.parse(word)
+//   let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
+//   return encrypted.ciphertext.toString().toUpperCase()
+// }
+// // 解密方法
+// export function Decrypt (word) {
+//   let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
+//   let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
+//   let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
+//   let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
+//   return decryptedStr.toString()
+// }
 // 加密方法
 export function Encrypt (word) {
-  let srcs = CryptoJS.enc.Utf8.parse(word)
-  let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
-  return encrypted.ciphertext.toString().toUpperCase()
+	const srcs = CryptoJS.enc.Utf8.parse(word)
+	const encrypted = CryptoJS.AES.encrypt(srcs, key, { iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding })
+	return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
 }
 // 解密方法
 export function Decrypt (word) {
-  let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
-  let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
-  let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
-  let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
-  return decryptedStr.toString()
+	const encryptedHexStr = CryptoJS.enc.Base64.parse(word)
+	const srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
+	const decrypt = CryptoJS.AES.decrypt(srcs, key, { iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding })
+	const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
+	return decryptedStr.toString()
 }

+ 3 - 2
src/views/home/index.vue

@@ -165,7 +165,7 @@ export default {
       }
 
       if (data !== '' && data !== undefined) {
-        let user = Decrypt(data)
+        let user = Decrypt(decodeURIComponent(data))
         console.log(user, 'token')
         Cookie.set('token', user)
       }
@@ -221,7 +221,8 @@ export default {
       const url = window.location.href
       if (url.indexOf(name) !== -1) {
         let r = urlObj.href.indexOf('#') > -1 ? urlObj.hash.split('?')[1].match(reg) : urlObj.search.substr(1).match(reg)
-        if (r != null) return unescape(r[2]); return null
+        if (r != null) return decodeURIComponent(r[2])
+				return null
       }
     }
   }