import { Config } from "../config"; import { rsaEncryptText, rsaDecryptText } from "@/uni_modules/laoqianjunzi-crypto"; export class JSEncrypt { /** * RSA公钥 */ private static readonly PUBLIC_KEY = Config.VITE_APP_RSA_PUBLIC_KEY; /** * RSA私钥 * ⚠ 前端一般不建议存储私钥 */ private static readonly PRIVATE_KEY = Config.VITE_APP_RSA_PRIVATE_KEY; /** * RSA加密 * * @param text 明文 * @returns Base64密文 */ static encrypt(text : string) : string { if (!text) { return ""; } return rsaEncryptText(JSEncrypt.PUBLIC_KEY, text, "base64"); } /** * RSA解密 * * @param cipherText Base64密文 * @returns 明文 */ static decrypt(cipherText : string) : string { if (!cipherText) { return ""; } return rsaDecryptText(JSEncrypt.PRIVATE_KEY, cipherText, "base64"); } }