第三方工具:wxmp-rsa - npm
1、构建 npm 包
2、安装
3、封装加密方法(rsa.js )
import WxmpRsa from 'wxmp-rsa'const privateKey = '秘钥字符串, 跟后端对接'const publicKey = '公钥字符串, 跟后端对接'const rsaEncrypt = (word) => { const encryptor = new WxmpRsa(); encryptor.setPublicKey(publicKey); return encryptor.encryptLong(word);}const rsaDecrypt = (word) => { const decryptor = new WxmpRsa(); decryptor.setPrivateKey(privateKey); return decryptor.decryptLong(word);}module.exports = { rsaEncrypt, rsaDecrypt}
4、使用
const RSA = require('./rsa')// 加密RSA.rsaEncrypt(''加密数据')// 解密RSA.rsaDecrypt('解密数据')
小程序官方方法:API安全 | 微信开放文档
来源地址:https://blog.csdn.net/weixin_46258341/article/details/131577648