From bc2ee69dd74aba0ba800de678c508fb81f941bb3 Mon Sep 17 00:00:00 2001 From: binbin_pan Date: Tue, 4 Jun 2024 14:01:19 +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 | 39 ++----------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/sgzb-ui/src/views/system/user/index.vue b/sgzb-ui/src/views/system/user/index.vue index e5914b51..f96ef246 100644 --- a/sgzb-ui/src/views/system/user/index.vue +++ b/sgzb-ui/src/views/system/user/index.vue @@ -429,7 +429,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 { encrypt } from '@/utils/jsencrypt' +import { decrypt } from '@/utils/jsencrypt' export default { name: 'User', @@ -588,7 +588,7 @@ export default { this.getList() this.getDeptTree() this.getConfigKey('sys.user.initPassword').then(response => { - this.initPassword = encrypt(response.msg) + this.initPassword = decrypt(response.msg) }) }, methods: { @@ -821,41 +821,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) - }, }, }