簡單網(wǎng)站制作成品推廣普通話的宣傳語
個(gè)人產(chǎn)生這個(gè)異常的原因:將歷史項(xiàng)目(vue2)的jsencrypt文件復(fù)制到新項(xiàng)目(vue3)里直接引用報(bào)錯(cuò)。存在兼容問題,需要重新安裝vue3版本的jsencrypt
安裝依賴
npm install jsencrypt
頁面引入
import { JSEncrypt } from 'jsencrypt'
簡單封裝
import {JSEncrypt
} from 'jsencrypt'
// 密鑰對(duì)生成 http://web.chacuo.net/netrsakeypair
const publicKey ='你的公鑰'
const privateKey = '你的私鑰'// 加密
export function encrypt(txt) {const encryptor = new JSEncrypt()encryptor.setPublicKey(publicKey) // 設(shè)置公鑰return encryptor.encrypt(txt) // 對(duì)數(shù)據(jù)進(jìn)行加密
}// 解密
export function decrypt(txt) {const encryptor = new JSEncrypt()encryptor.setPrivateKey(privateKey) // 設(shè)置私鑰return encryptor.decrypt(txt) // 對(duì)數(shù)據(jù)進(jìn)行解密
}
具體使用
<script>import {encrypt} from '@/utils/rsa/jsencrypt-vue3.js'export default {data() {return {}},methods: {startLogin() { var param = {username: 'xxxxx',// 調(diào)用加密方法,完成密碼的rsa加密password: encrypt('xxxxxx')}}}}
</script>
參考資料
uniapp vue3版本 Android 引用 jsencrypt加密庫 報(bào)錯(cuò)問題 “default“ is not exported by,解決方法
前端VUE3使用RSA加密向后端傳輸密碼
微信小程序使用npm方式增加jsencrypt rsa加密驗(yàn)證