RSA前端加密(vue项目登陆)

1,安装插件

npm install jsencrypt --save

2,安装成功之后,在main.js文件引入

import JSEncrypt from 'jsencrypt';//引入模块
Vue.prototype.$jsEncrypt = JSEncrypt;//配置全局变量

3,在需要使用的组件(本文以登录页面对账号和密码进行了加密)

 getPublicKey({}).then((res)=>{//请求公钥接口
                            const jse = new this.$jsEncrypt()
                            jse.setPublicKey(res)//配置公钥
                            var aesuncrypt_Acount = jse.encrypt(this.ruleForm.username)//加密账号
                            var aesuncrypt_pwd = jse.encrypt(this.ruleForm.password)//加密密码
                            userlogin({//登录接口
                                account:aesuncrypt_Acount,
                                pwd:aesuncrypt_pwd,
                            }).then((res)=>{
                                if(res.success){
                             //登录成功之后的操作
                                    this.$router.push('/');
                                }else{
                                    //登录失败的操作
........
                                }
                            })
                        })

版权声明:本文为qq_43618030原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。