创建rsa加解密工具类,
可以通过传入需要加密的内容然后返回加解密后的数据, 返回的数据统一为string类型, 后续需要优化为UTSJSONObject
This commit is contained in:
@@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user