使用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; }
详细可见 https://github.com/travist/jsencrypt
原文:https://www.cnblogs.com/lw5116/p/12163436.html