添加jsencrypt实现参数的前端加密
This commit is contained in:
parent
3af0158d40
commit
9f97fd0953
|
@ -40,7 +40,7 @@
|
||||||
"url": "https://gitee.com/y_project/RuoYi-Vue.git"
|
"url": "https://gitee.com/y_project/RuoYi-Vue.git"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@riophae/vue-treeselect": "0.1.0",
|
"@riophae/vue-treeselect": "0.4.0",
|
||||||
"vue-quill-editor": "3.0.6",
|
"vue-quill-editor": "3.0.6",
|
||||||
"vue-cropper": "0.4.9",
|
"vue-cropper": "0.4.9",
|
||||||
"axios": "0.18.1",
|
"axios": "0.18.1",
|
||||||
|
@ -48,6 +48,7 @@
|
||||||
"element-ui": "2.11.1",
|
"element-ui": "2.11.1",
|
||||||
"fuse.js": "3.4.4",
|
"fuse.js": "3.4.4",
|
||||||
"js-cookie": "2.2.0",
|
"js-cookie": "2.2.0",
|
||||||
|
"jsencrypt": "3.0.0-rc.1",
|
||||||
"normalize.css": "7.0.0",
|
"normalize.css": "7.0.0",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"path-to-regexp": "2.4.0",
|
"path-to-regexp": "2.4.0",
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
import JSEncrypt from 'jsencrypt/bin/jsencrypt'
|
||||||
|
|
||||||
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
|
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANL378k3RiZHWx5AfJqdH9xRNBmD9wGD\n' +
|
||||||
|
'2iRe41HdTNF8RUhNnHit5NpMNtGL0NPTSSpPjjI1kJfVorRvaQerUgkCAwEAAQ=='
|
||||||
|
|
||||||
|
const privateKey = 'MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8\n' +
|
||||||
|
'mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9p\n' +
|
||||||
|
'B6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue\n' +
|
||||||
|
'/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZ\n' +
|
||||||
|
'UBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6\n' +
|
||||||
|
'vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha\n' +
|
||||||
|
'4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3\n' +
|
||||||
|
'tTbklZkD2A=='
|
||||||
|
|
||||||
|
// 加密
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { getCodeImg } from "@/api/login";
|
import { getCodeImg } from "@/api/login";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
|
@ -108,7 +109,7 @@ export default {
|
||||||
const rememberMe = Cookies.get('rememberMe')
|
const rememberMe = Cookies.get('rememberMe')
|
||||||
this.loginForm = {
|
this.loginForm = {
|
||||||
username: username === undefined ? this.loginForm.username : username,
|
username: username === undefined ? this.loginForm.username : username,
|
||||||
password: password === undefined ? this.loginForm.password : password,
|
password: password === undefined ? this.loginForm.password : decrypt(password),
|
||||||
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -118,7 +119,7 @@ export default {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
if (this.loginForm.rememberMe) {
|
if (this.loginForm.rememberMe) {
|
||||||
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
||||||
Cookies.set("password", this.loginForm.password, { expires: 30 });
|
Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
||||||
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
||||||
} else {
|
} else {
|
||||||
Cookies.remove("username");
|
Cookies.remove("username");
|
||||||
|
|
Loading…
Reference in New Issue