vue登陆修改密码等加密(禁止明文传输)

1.下载加密插件,终端运行

复制代码
yarn add jsencrypt

2.配置加密信息文件rsaEncrypt.js放到utils中,代码如下

复制代码
import JSEncrypt from 'jsencrypt/bin/jsencrypt'

// 密钥对生成网址 http://web.chacuo.net/netrsakeypair

const publicKey = 'MIGfMA0GCSqGSIb3DQEBxxxxxxxxxxxx'

const privateKey = 'MIICdgIBADANBgxxxxxxxxx'

// 加密方法
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)
}

3.登陆 ,修改密码等地方使用,注意后端也要对应配置

复制代码
import { encrypt } from "@utils/rsaEncrypt";  


const toLogin = ()=>{

proxy.$refs.loginFormRef.validate((valid) => {
    const form = {
      account: loginForm.account,
      password: encrypt(loginForm.password),
      rememberMe: loginForm.rememberMe,
      code: loginForm.code,
      uuid: loginForm.uuid,
    };
    if (valid) {
      state.loading = true;
      userStore
        .login(form)
        .then(() => {
          state.loading = false;
          router.push({ path: proxy.$route.query?.redirect || "/index" });
        })
        .catch(() => {
          state.loading = false;
          getCode();
        });
    }
  });
}
相关推荐
哈__5 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-device-info
javascript·react native·react.js
前端布鲁伊8 分钟前
零代码上线一个图片处理网站,我是如何使唤AI干活的?
前端·ai编程
庄小焱9 分钟前
React——React基础语法(2)
前端·javascript·react.js
终端鹿12 分钟前
Vue3 核心 API 深度解析:ref / reactive / computed / watch
前端·javascript·vue.js
console.log('npc')19 分钟前
partial在react接口定义中是什么意思
前端·javascript·typescript
SuperEugene20 分钟前
前端 utils 工具函数规范:拆分 / 命名 / 复用全指南,避开全局污染等高频坑|编码语法规范篇
开发语言·前端·javascript
C澒23 分钟前
微前端容器标准化 —— 公共能力篇:通用请求
前端·架构
llxxyy卢32 分钟前
web部分中等题目
android·前端
若惜41 分钟前
selenium自动化测试web自动化测试 框架封装Pom
前端·python·selenium
Amumu121381 小时前
Js:内置对象
开发语言·前端·javascript