前端引入jsrsasign进行RSA加密,登录Action增加RSA密码加密
This commit is contained in:
parent
959e8976e0
commit
3e89c69a95
@ -30,6 +30,7 @@
|
|||||||
"js-cookie": "3.0.1",
|
"js-cookie": "3.0.1",
|
||||||
"js-md5": "^0.7.3",
|
"js-md5": "^0.7.3",
|
||||||
"jsencrypt": "3.2.1",
|
"jsencrypt": "3.2.1",
|
||||||
|
"jsrsasign": "^10.8.6",
|
||||||
"md-editor-v3": "^1.11.11",
|
"md-editor-v3": "^1.11.11",
|
||||||
"nprogress": "0.2.0",
|
"nprogress": "0.2.0",
|
||||||
"pinia": "^2.0.33",
|
"pinia": "^2.0.33",
|
||||||
|
|||||||
@ -67,3 +67,10 @@ export function oauthCallback(data, params) {
|
|||||||
params: params
|
params: params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRsaKey() {
|
||||||
|
return request({
|
||||||
|
url: '/getRsaKey',
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { login, logout, getInfo, oauthCallback } from '@/api/system/login'
|
import { login, logout, getInfo, oauthCallback, getRsaKey } from '@/api/system/login'
|
||||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||||
import defAva from '@/assets/images/profile.jpg'
|
import defAva from '@/assets/images/profile.jpg'
|
||||||
import md5 from 'js-md5'
|
import { encryptByPublicKey } from '@/utils/jsencrypt'
|
||||||
const useUserStore = defineStore('user', {
|
const useUserStore = defineStore('user', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
userInfo: '',
|
userInfo: '',
|
||||||
@ -20,11 +20,13 @@ const useUserStore = defineStore('user', {
|
|||||||
},
|
},
|
||||||
// 登录
|
// 登录
|
||||||
login(userInfo) {
|
login(userInfo) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
getRsaKey().then((response) => {
|
||||||
|
const publicKey = response.data.publicKey
|
||||||
const username = userInfo.username.trim()
|
const username = userInfo.username.trim()
|
||||||
const password = md5(userInfo.password)
|
const password = encryptByPublicKey(userInfo.password, publicKey)
|
||||||
const code = userInfo.code
|
const code = userInfo.code
|
||||||
const uuid = userInfo.uuid
|
const uuid = userInfo.uuid
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
login(username, password, code, uuid)
|
login(username, password, code, uuid)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
@ -40,6 +42,7 @@ const useUserStore = defineStore('user', {
|
|||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 三方授权登录
|
* 三方授权登录
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
import JSEncrypt from 'jsencrypt/bin/jsencrypt.min'
|
||||||
|
import jsrsasign from 'jsrsasign'
|
||||||
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
// 密钥对生成 http://web.chacuo.net/netrsakeypair
|
||||||
|
|
||||||
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALj0zjON+EVdBsnMcR4Uj+jOYgp5ZipftQZ1utW8KvVioz+RSaotF1JHt59q9SC/mZcWWpbpcEqQ3WyyyCC33msCAwEAAQ=='
|
const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALj0zjON+EVdBsnMcR4Uj+jOYgp5ZipftQZ1utW8KvVioz+RSaotF1JHt59q9SC/mZcWWpbpcEqQ3WyyyCC33msCAwEAAQ=='
|
||||||
@ -20,3 +20,8 @@ export function decrypt(txt) {
|
|||||||
encryptor.setPrivateKey(privateKey) // 设置私钥
|
encryptor.setPrivateKey(privateKey) // 设置私钥
|
||||||
return encryptor.decrypt(txt) // 对数据进行解密
|
return encryptor.decrypt(txt) // 对数据进行解密
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const encryptByPublicKey = (txt, publicKey) => {
|
||||||
|
const pubKey = jsrsasign.KEYUTIL.getKey(publicKey)
|
||||||
|
return jsrsasign.KJUR.crypto.Cipher.encrypt(txt, pubKey)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user