0
点赞
收藏
分享

微信扫一扫

关于前端--RSA加密(对登录密码加密)

眸晓 2022-01-17 阅读 65

安装

 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'

举报

相关推荐

0 条评论