Skip to content

Commit 92e8a91

Browse files
committed
feat: update encryption process to use UTF-8 encoding for login form data
1 parent 9faebd8 commit 92e8a91

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

ui/src/views/chat/user-login/index.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ const loginHandle = () => {
252252
})
253253
} else {
254254
const publicKey = forge.pki.publicKeyFromPem(chatUser?.chat_profile?.rasKey as any);
255-
const encrypted = publicKey.encrypt(JSON.stringify(loginForm.value), 'RSAES-PKCS1-V1_5');
255+
const jsonData = JSON.stringify(loginForm.value);
256+
const utf8Bytes = forge.util.encodeUtf8(jsonData);
257+
const encrypted = publicKey.encrypt(utf8Bytes, 'RSAES-PKCS1-V1_5');
256258
const encryptedBase64 = forge.util.encode64(encrypted);
257259
chatUser.login({
258260
encryptedData: encryptedBase64,
@@ -438,10 +440,10 @@ onBeforeMount(() => {
438440
console.log('DingTalk client request success:', res)
439441
chatUser.dingOauth2Callback(res.code, accessToken).then(() => {
440442
router.push({
441-
name: 'chat',
442-
params: {accessToken: accessToken},
443-
query: route.query,
444-
})
443+
name: 'chat',
444+
params: {accessToken: accessToken},
445+
query: route.query,
446+
})
445447
})
446448
})
447449
}

ui/src/views/login/index.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ const loginHandle = () => {
201201
})
202202
} else {
203203
const publicKey = forge.pki.publicKeyFromPem(user.rasKey);
204-
const encrypted = publicKey.encrypt(JSON.stringify(loginForm.value), 'RSAES-PKCS1-V1_5');
204+
// 转换为UTF-8编码后再加密
205+
const jsonData = JSON.stringify(loginForm.value);
206+
const utf8Bytes = forge.util.encodeUtf8(jsonData);
207+
const encrypted = publicKey.encrypt(utf8Bytes, 'RSAES-PKCS1-V1_5');
205208
const encryptedBase64 = forge.util.encode64(encrypted);
206209
login
207210
.asyncLogin({encryptedData: encryptedBase64, username: loginForm.value.username})

0 commit comments

Comments
 (0)