From 4c301e0d13fdfdb8ab659ca990f06fc741260ca1 Mon Sep 17 00:00:00 2001 From: TiaStars Date: Fri, 22 Nov 2024 15:16:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=8A=A0=E5=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/views/auditPages/unitManagement/index.vue | 2 +- src/views/login.vue | 30 ++++++++++++++++--- src/views/system/user/index.vue | 4 +-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 963a734..b92f288 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "js-beautify": "1.13.0", "js-cookie": "3.0.1", "jsencrypt": "3.0.0-rc.1", + "node-forge": "^1.3.1", "nprogress": "0.2.0", "quill": "2.0.2", "screenfull": "5.0.2", diff --git a/src/views/auditPages/unitManagement/index.vue b/src/views/auditPages/unitManagement/index.vue index 71d017f..5e31286 100644 --- a/src/views/auditPages/unitManagement/index.vue +++ b/src/views/auditPages/unitManagement/index.vue @@ -586,7 +586,7 @@ export default { this.$router.go(-1); return; } - if(this.ruleForm.ssqy.length > 0) { + if(this.ruleForm.ssqy?.length > 0) { this.ruleForm.ssqyprovince = this.ruleForm.ssqy[0] this.ruleForm.ssqycity = this.ruleForm.ssqy[1] this.ruleForm.ssqycounty = this.ruleForm.ssqy[2] diff --git a/src/views/login.vue b/src/views/login.vue index 72b1ebd..5fb37d1 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -55,9 +55,9 @@ - @@ -65,6 +65,7 @@ import { getCodeImg } from "@/api/login"; import Cookies from "js-cookie"; import { encrypt, decrypt } from '@/utils/jsencrypt' +import forge from 'node-forge' export default { name: "Login", @@ -92,7 +93,8 @@ export default { captchaEnabled: true, // 注册开关 register: false, - redirect: undefined + redirect: undefined, + publicKey:`MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl8bS1kYTiMhIS5MZU253bc0ukaxrA1lfCziABFxQrC2c09tMrQGjuH6V1x2ofNBMGhOD9uWN/qkAQy/HwOe/NKUqCw6N0ov6guSrqMDW/BdZ3Bl0rmM1/95jTC1xffFFvej7xWNffIbaPI+bJ4WLX9NViNi9HmT0BRNzJ4d2R86LPPCa+bxLaPjsh2R2tBkbLkUot9769aJaPPiwPCZHMkuQenjHSmpWL0okleqMH8EGX7j6A5A/4IUXPMNKMMzkiSRpsIJ65GJmDAbnR3ZXRfC8MzVBBJB6zr5N0F4N9xZfF+JS/Yx726tCu+rA6GDCyTxtQ/wnKpPdwFP5nUWCWQIDAQAB` }; }, watch: { @@ -140,7 +142,27 @@ export default { Cookies.remove("password"); Cookies.remove('rememberMe'); } - this.$store.dispatch("Login", this.loginForm).then(() => { + // 生成一个 2048 位的 RSA 密钥对 + const lines = []; + lines.push('-----BEGIN PUBLIC KEY-----'); + for (let i = 0; i < this.publicKey.length; i += 64) { + lines.push(this.publicKey.slice(i, i + 64)); + } + lines.push('-----END PUBLIC KEY-----'); + lines.join('\n') + const publicKey = forge.pki.publicKeyFromPem(lines.join('\n')); + // 将待加密的字符串转换为字节数组 + var dataBytes = forge.util.encodeUtf8(this.loginForm.password); + // 加密数据 + var encryptedBytes = publicKey.encrypt(dataBytes, 'RSA-OAEP', { + md: forge.md.sha256.create(), + mgf1: { + md: forge.md.sha1.create() + } + }); + // 将加密后的字节数组转换为 Base64 编码的字符串 + var encryptedBase64 = forge.util.encode64(encryptedBytes); + this.$store.dispatch("Login", {...this.loginForm, password: encryptedBase64}).then(() => { this.$router.push({ path: this.redirect || "/" }).catch(()=>{}); }).catch(() => { this.loading = false; diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 7f55ca1..576b0d6 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -252,8 +252,8 @@