From 0cb415297c5421428b3213c3748d386841c5424d Mon Sep 17 00:00:00 2001 From: xiaozhi <1822691309@qq.com> Date: Sun, 7 Jun 2026 11:05:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BArsa=E5=8A=A0=E8=A7=A3?= =?UTF-8?q?=E5=AF=86=E5=B7=A5=E5=85=B7=E7=B1=BB=EF=BC=8C=20=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E9=80=9A=E8=BF=87=E4=BC=A0=E5=85=A5=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E7=9A=84=E5=86=85=E5=AE=B9=E7=84=B6=E5=90=8E?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=8A=A0=E8=A7=A3=E5=AF=86=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=20=E8=BF=94=E5=9B=9E=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=9F=E4=B8=80=E4=B8=BAstring=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=20=E5=90=8E=E7=BB=AD=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=BAUTSJSONObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/jsencrypt.uts | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 utils/jsencrypt.uts diff --git a/utils/jsencrypt.uts b/utils/jsencrypt.uts new file mode 100644 index 0000000..3c5953a --- /dev/null +++ b/utils/jsencrypt.uts @@ -0,0 +1,42 @@ +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"); + } +} \ No newline at end of file