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();
        });
    }
  });
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-01 13:52:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-01 13:52:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-02-01 13:52:01       82 阅读
  4. Python语言-面向对象

    2024-02-01 13:52:01       91 阅读

热门阅读

  1. Python 将文本转换成语音播放 pyttsx3

    2024-02-01 13:52:01       48 阅读
  2. 【GPU驱动开发】- GPU架构流程

    2024-02-01 13:52:01       46 阅读
  3. go语言-字符串处理常用函数

    2024-02-01 13:52:01       50 阅读
  4. P3654 First Step (ファーストステップ)题解

    2024-02-01 13:52:01       52 阅读
  5. 你保存alzet渗透泵中文说明书了吗?

    2024-02-01 13:52:01       50 阅读
  6. 关于js的动画效果

    2024-02-01 13:52:01       51 阅读
  7. C语言函数指针与回调函数

    2024-02-01 13:52:01       46 阅读
  8. 30个常用的lodash工具函数

    2024-02-01 13:52:01       53 阅读
  9. CG-70B 双轴普及型倾角传感器

    2024-02-01 13:52:01       56 阅读
  10. 一篇文章带你入门使用Linux中的curl命令

    2024-02-01 13:52:01       54 阅读
  11. 我的数据结构c(给自己用的)

    2024-02-01 13:52:01       49 阅读