From 92e8a9105f912c09c5a563a81c4ed0af5a7b79b1 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 22 Oct 2025 16:40:46 +0800 Subject: [PATCH] feat: update encryption process to use UTF-8 encoding for login form data --- ui/src/views/chat/user-login/index.vue | 12 +++++++----- ui/src/views/login/index.vue | 5 ++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ui/src/views/chat/user-login/index.vue b/ui/src/views/chat/user-login/index.vue index 702009be0..75d03dc03 100644 --- a/ui/src/views/chat/user-login/index.vue +++ b/ui/src/views/chat/user-login/index.vue @@ -252,7 +252,9 @@ const loginHandle = () => { }) } else { const publicKey = forge.pki.publicKeyFromPem(chatUser?.chat_profile?.rasKey as any); - const encrypted = publicKey.encrypt(JSON.stringify(loginForm.value), 'RSAES-PKCS1-V1_5'); + const jsonData = JSON.stringify(loginForm.value); + const utf8Bytes = forge.util.encodeUtf8(jsonData); + const encrypted = publicKey.encrypt(utf8Bytes, 'RSAES-PKCS1-V1_5'); const encryptedBase64 = forge.util.encode64(encrypted); chatUser.login({ encryptedData: encryptedBase64, @@ -438,10 +440,10 @@ onBeforeMount(() => { console.log('DingTalk client request success:', res) chatUser.dingOauth2Callback(res.code, accessToken).then(() => { router.push({ - name: 'chat', - params: {accessToken: accessToken}, - query: route.query, - }) + name: 'chat', + params: {accessToken: accessToken}, + query: route.query, + }) }) }) } diff --git a/ui/src/views/login/index.vue b/ui/src/views/login/index.vue index 735d2b506..c8d36a029 100644 --- a/ui/src/views/login/index.vue +++ b/ui/src/views/login/index.vue @@ -201,7 +201,10 @@ const loginHandle = () => { }) } else { const publicKey = forge.pki.publicKeyFromPem(user.rasKey); - const encrypted = publicKey.encrypt(JSON.stringify(loginForm.value), 'RSAES-PKCS1-V1_5'); + // 转换为UTF-8编码后再加密 + const jsonData = JSON.stringify(loginForm.value); + const utf8Bytes = forge.util.encodeUtf8(jsonData); + const encrypted = publicKey.encrypt(utf8Bytes, 'RSAES-PKCS1-V1_5'); const encryptedBase64 = forge.util.encode64(encrypted); login .asyncLogin({encryptedData: encryptedBase64, username: loginForm.value.username})