Files
xiaozhi-user-uniappx/utils/jsencrypt.uts
T
xiaozhi 0cb415297c 创建rsa加解密工具类,
可以通过传入需要加密的内容然后返回加解密后的数据,
返回的数据统一为string类型,
后续需要优化为UTSJSONObject
2026-06-07 11:05:33 +08:00

42 lines
844 B
Plaintext

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");
}
}