使用jsencrypt
import { JSEncrypt } from "jsencrypt"; /** * * @param {文本值} value * @param {公钥} publicKey */ function encryptPublic(value, publicKey) { // 使用公钥加密,default_key_size可为512,1024,2048等 let encrypt = new JSEncrypt({ default_key_size: 2048 }); encrypt.setPublicKey(publicKey); let encrypted = encrypt.encrypt(value); return encrypted; }