本文共 713 字,大约阅读时间需要 2 分钟。
在Uniapp项目中集成JSEncrypt进行加密处理,可以按照以下步骤进行操作:
yarn add jsencrypt --type=dep 或者 npm install jsencrypt --save-dev
node_modules文件夹,找到jsencrypt包:cd node_modules cd jsencrypt
将jsencrypt.js文件从bin文件夹中解压出来,替换原有文件。
import JSEncrypt from 'jsencrypt'
methods: { encryptedData(publicKey, data) { const encryptor = new JSEncrypt() encryptor.setPublicKey(publicKey) return encryptor.encrypt(data) }, decryptData(privateKey, secretWord) { const decrypt = new JSEncrypt() decrypt.setPrivateKey(privateKey) return decrypt.decrypt(secretWord) }} 注意:确保在项目中正确导入并设置公钥和私钥,JSEncrypt库能够正常运行。
转载地址:http://xxec.baihongyu.com/