From d02a1558524997671dd7c2e6dd5250beeab9fba1 Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Tue, 4 Jun 2024 14:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=AF=86=E5=88=9D=E5=A7=8B=E5=AF=86?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/views/system/user/index.vue | 59 +------------------------ 1 file changed, 2 insertions(+), 57 deletions(-) diff --git a/sgzb-ui/src/views/system/user/index.vue b/sgzb-ui/src/views/system/user/index.vue index 3d3cb587..0d92c0e9 100644 --- a/sgzb-ui/src/views/system/user/index.vue +++ b/sgzb-ui/src/views/system/user/index.vue @@ -551,6 +551,7 @@ import { getToken } from '@/utils/auth' import Treeselect from '@riophae/vue-treeselect' import '@riophae/vue-treeselect/dist/vue-treeselect.css' import { validPassword } from '@/utils/validate' +import { decrypt } from '@/utils/jsencrypt.js' export default { name: 'User', @@ -714,14 +715,7 @@ export default { this.getList() this.getDeptTree() this.getConfigKey('sys.user.initPassword').then((response) => { - this.decryptData(response.msg, this.secretKey) - .then((data) => { - console.log('🚀 ~ this.getConfigKey ~ data:', data) - this.initPassword = data - }) - .catch((error) => { - console.log('🚀 ~ this.getConfigKey ~ error:', error) - }) + this.initPassword = decrypt(response.msg) }) }, methods: { @@ -962,55 +956,6 @@ export default { submitFileForm() { this.$refs.upload.submit() }, - // 加密 - async encryptData(data, keyStr) { - const keyUint8 = new TextEncoder().encode(keyStr) - const key = await crypto.subtle.importKey( - 'raw', - keyUint8, - { name: 'AES-CBC', length: 256 }, - false, - ['encrypt'], - ) - - const iv = crypto.getRandomValues(new Uint8Array(16)) - const cipherTextBuffer = await crypto.subtle.encrypt( - { name: 'AES-CBC', iv }, - key, - new TextEncoder().encode(data), - ) - - const combined = new Uint8Array( - iv.length + cipherTextBuffer.byteLength, - ) - combined.set(iv, 0) - combined.set(new Uint8Array(cipherTextBuffer), iv.length) - - return btoa(String.fromCharCode.apply(null, combined)) - }, - // 解密 - async decryptData(encryptedData, keyStr) { - const keyUint8 = new TextEncoder().encode(keyStr) - const encryptedBytes = Uint8Array.from(atob(encryptedData), (c) => - c.charCodeAt(0), - ) - - const key = await crypto.subtle.importKey( - 'raw', - keyUint8, - { name: 'AES-CBC', length: 256 }, // 假设后端使用了CBC模式,需要调整为实际使用的模式 - false, - ['decrypt'], - ) - - const decryptedData = await crypto.subtle.decrypt( - { name: 'AES-CBC', iv: new Uint8Array(16) }, // 实际使用时需要正确的IV,这里仅为示例 - key, - encryptedBytes, - ) - - return new TextDecoder().decode(decryptedData) - }, }, }