安装
npm install jsencrypt
1.在utils文件中封装一个jsencrypt.js文件
密匙对生成链接:http://web.chacuo.net/netrsakeypair
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
// 密钥对生成 http://web.chacuo.net/netrsakeypair
const publicKey = '公钥'
const privateKey = '私钥'
// 加密
export function encrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPublicKey(publicKey) // 设置公钥
return encryptor.encrypt(txt) // 对需要加密的数据进行加密
}
// 解密
export function decrypt(txt) {
const encryptor = new JSEncrypt()
encryptor.setPrivateKey(privateKey) // 设置私钥
return encryptor.decrypt(txt)// 对加密的数据进行解密
}
2.基本使用
在login.vue文件中
import {encrypt, decrypt} from '@/utils/jsencrypt'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)