import JSEncrypt from 'jsencrypt' import request from '@/utils/http' /** * Web 端登录:拉取 RSA 公钥后加密 { username, password, ts },与后端 PKCS#1 v1.5 解密一致。 */ export async function buildWebEncryptedLoginBody(username: string, password: string) { const { publicKeyPem } = await request.get<{ publicKeyPem: string }>({ url: '/web/auth/login-rsa-public-key' }) const crypt = new JSEncrypt() crypt.setPublicKey(publicKeyPem) const payload = JSON.stringify({ username, password, ts: Date.now() }) const encryptedLogin = crypt.encrypt(payload) if (!encryptedLogin) { throw new Error('登录加密失败,请重试') } return { encryptedLogin } }