用户新增传输过程加密

This commit is contained in:
zer0Black
2022-02-24 21:47:08 +08:00
parent 5d221272e4
commit 8749d950f3
11 changed files with 112 additions and 6092 deletions
+2 -2
View File
@@ -2037,8 +2037,8 @@ CREATE TABLE `sys_user` (
`avatar` varchar(255) DEFAULT NULL COMMENT '头像',
`birthday` datetime DEFAULT NULL COMMENT '生日',
`sex` tinyint(1) DEFAULT NULL COMMENT '性别(0-默认未知,1-男,2-女)',
`email` varchar(45) DEFAULT NULL COMMENT '电子邮件',
`phone` varchar(45) DEFAULT NULL COMMENT '电话',
`email` varchar(200) DEFAULT NULL COMMENT '电子邮件',
`phone` varchar(200) DEFAULT NULL COMMENT '电话',
`org_code` varchar(64) DEFAULT NULL COMMENT '机构编码',
`status` tinyint(1) DEFAULT NULL COMMENT '性别(1-正常,2-冻结)',
`del_flag` tinyint(1) DEFAULT NULL COMMENT '删除状态(0-正常,1-已删除)',
@@ -2,6 +2,7 @@ package com.jero.modules.system.controller;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@@ -144,15 +145,17 @@ public class SysUserController {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
try {
//1:先用私钥解密数据
String email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
String phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
if (StrUtil.isNotEmpty(user.getEmail())){
String email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
// email = PasswordUtil.encrypt(email);
user.setEmail(email);
}
//3:把数据加密在放回来
email = PasswordUtil.encrypt(email);
phone = PasswordUtil.encrypt(phone);
user.setEmail(email);
user.setPhone(phone);
if (StrUtil.isNotEmpty(user.getPhone())){
String phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
// phone = PasswordUtil.encrypt(phone);
user.setPhone(phone);
}
// 密码加盐
String password = CommonUtils.decryptBtRsaPriKey(user.getPassword(), rsaPrivateKey);
@@ -192,18 +195,23 @@ public class SysUserController {
result.error500("未找到对应实体");
}else {
SysUser user = JSON.parseObject(jsonObject.toJSONString(), SysUser.class);
String email;
String phone;
String email = null;
String phone = null;
try {
//1:先用私钥解密数据
email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
if (StrUtil.isNotEmpty(user.getEmail())){
email = CommonUtils.decryptBtRsaPriKey(user.getEmail(), rsaPrivateKey);
}
if (StrUtil.isNotEmpty(user.getPhone())){
phone = CommonUtils.decryptBtRsaPriKey(user.getPhone(), rsaPrivateKey);
}
} catch (Exception e) {
throw new JeroBootException("解密失败!", e);
}
//3:把数据加密在放回来
email = PasswordUtil.encrypt(email);
phone = PasswordUtil.encrypt(phone);
// 3:把数据加密在放回来
// email = PasswordUtil.encrypt(email);
// phone = PasswordUtil.encrypt(phone);
user.setEmail(email);
user.setPhone(phone);
user.setUpdateTime(new Date());
@@ -175,4 +175,5 @@ public class SysUser implements Serializable {
/**设备id uniapp推送用*/
private String clientId;
}
@@ -35,7 +35,7 @@
</select>
<!--根据parent_id查询下级部门-->
<select id="queryTreeListByPid" parameterType="Object" resultType="org.jeecg.modules.system.entity.SysDepart">
<select id="queryTreeListByPid" parameterType="Object" resultType="com.jero.modules.system.entity.SysDepart">
SELECT * FROM sys_depart where del_flag = '0'
<choose>
<when test="parentId != null and parentId != ''">
@@ -49,7 +49,7 @@
</select>
<!-- 根据OrgCod查询公司信息 -->
<select id="queryCompByOrgCode" resultType="org.jeecg.modules.system.entity.SysDepart">
<select id="queryCompByOrgCode" resultType="com.jero.modules.system.entity.SysDepart">
select * from sys_depart where del_flag = '0' and org_category='1' and org_code= #{orgCode,jdbcType=VARCHAR}
</select>
</mapper>
@@ -131,7 +131,7 @@ spring:
connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
datasource:
master:
url: jdbc:mysql://10.0.3.44:3306/jero-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
url: jdbc:mysql://10.10.10.44:3306/jero-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
-15
View File
@@ -71,19 +71,4 @@ export function thirdLogin(token,thirdType) {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
/**
* 获取RSA公钥
* @returns {*}
*/
export function getRSAPublicKey() {
return axios({
url: `/sys/getRSAPublicKey`,
method: 'get',
timeout: 5000,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
+16
View File
@@ -0,0 +1,16 @@
import { axios } from '@/utils/request'
/**
* 获取RSA公钥
* @returns {*}
*/
export function getRSAPublicKey() {
return axios({
url: `/sys/getRSAPublicKey`,
method: 'get',
timeout: 5000,
headers: {
'Content-Type': 'application/json;charset=UTF-8'
}
})
}
File diff suppressed because it is too large Load Diff
-20
View File
@@ -1,20 +0,0 @@
/**
* 功能模块
* @type {{LEAVE_EARLY: {text: string, value: string}, LATE: {text: string, value: string}, ABSENT: {text: string, value: string}, NO_SIGN: {text: string, value: string}, NORMAL: {text: string, value: string}}}
*/
export const FunctionEnum = {
EoaCmsBanner: { path: 'modules/eoa/cmsoa/modules/EoaCmsBanner', formData: 'carouselImg' },
EoaCmsNewsInfo: { path: 'modules/eoa/cmsoa/modules/EoaCmsNewsInfo', formData: 'newsInfo' },
EoaCmsRuleInfo: { path: 'modules/eoa/cmsoa/modules/EoaCmsRuleInfo', formData: 'ruleDownInfo' },
EoaCmsSignNews: { path: 'modules/eoa/cmsoa/modules/EoaCmsSignNews', formData: 'signNews' },
EoaCmsUserNotice: { path: 'modules/eoa/cmsoa/modules/EoaCmsUserNotice', formData: 'userNotice' },
EoaCmsPlan: { path: 'modules/eoa/cmsoa/modules/EoaCmsPlan', formData: '' },
EoaCmsLink: { path: 'modules/eoa/cmsoa/modules/EoaCmsLink', formData: '' },
EoaCmsCommUse:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsCommUse', formData: '' },
EoaCmsMyProcess:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsMyProcess', formData: '' },
EoaCmsApplyProcess:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsApplyProcess', formData: '' },
EoaCmsProcessNotice:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsProcessNotice', formData: '' },
EoaCmsProcessChatData:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsProcessChatData', formData: '' },
EoaCmsProcessTypeChat:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsProcessTypeChat', formData: '' },
EoaCmsEmail:{ path: 'modules/eoa/cmsbpm/modules/EoaCmsEmail', formData: '' },
}
+65 -31
View File
@@ -134,6 +134,8 @@ import { getAction } from '@/api/manage'
import { addUser,editUser,queryUserRole,queryall } from '@/api/api'
import { disabledAuthFilter } from "@/utils/authFilter"
import { duplicateCheck } from '@/api/api'
import { getRSAPublicKey } from '@/utils/encryption.js'
import { JSEncrypt } from 'jsencrypt'
export default {
name: "UserModal",
@@ -189,6 +191,7 @@ import { duplicateCheck } from '@/api/api'
tenantsOptions: [],
rolesOptions:[],
nextDepartOptions:[],
rsaPublicKey:'',
}
},
created () {
@@ -196,7 +199,6 @@ import { duplicateCheck } from '@/api/api'
this.headers = {"X-Access-Token":token}
this.initRoleList()
this.initTenantList()
},
computed:{
uploadAction:function () {
@@ -324,35 +326,67 @@ import { duplicateCheck } from '@/api/api'
moment,
handleSubmit () {
const that = this;
// 触发表单验证
this.$refs.form.validate(valid => {
if (valid) {
that.confirmLoading = true;
//如果是上级择传入departIds,否则为空
if(this.model.userIdentity!==2){
this.model.departIds="";
}
let obj;
if(!this.model.id){
this.model.id = this.userId;
obj=addUser(this.model);
}else{
obj=editUser(this.model);
}
obj.then((res)=>{
if(res.success){
that.$message.success(res.message);
that.$emit('ok');
}else{
that.$message.warning(res.message);
//先拉取秘钥
getRSAPublicKey().then(res => {
debugger
this.rsaPublicKey = res.result
// 触发表单验证
this.$refs.form.validate(valid => {
if (valid) {
that.confirmLoading = true;
//如果是上级择传入departIds,否则为空
if(this.model.userIdentity!==2){
this.model.departIds="";
}
}).finally(() => {
that.confirmLoading = false;
that.close();
})
}else{
return false;
}
// 对密码邮箱手机号进行加密
let encrypt = new JSEncrypt();
encrypt.setPublicKey(that.rsaPublicKey);
if (this.model.password != ""
&& this.model.password != null
&& this.model.password != undefined){
this.model.password = encrypt.encrypt(this.model.password)
}
if (this.model.phone != ""
&& this.model.phone != null
&& this.model.phone != undefined){
this.model.phone = encrypt.encrypt(this.model.phone)
}
if (this.model.email != ""
&& this.model.email != null
&& this.model.email != undefined){
this.model.email = encrypt.encrypt(this.model.email)
}
this.model.rsaPublicKey = that.rsaPublicKey
let obj;
if(!this.model.id){
this.model.id = this.userId;
obj=addUser(this.model);
}else{
obj=editUser(this.model);
}
obj.then((res)=>{
if(res.success){
that.$message.success(res.message);
that.$emit('ok');
}else{
that.$message.warning(res.message);
}
}).finally(() => {
that.confirmLoading = false;
that.close();
})
}else{
return false;
}
})
})
},
handleCancel () {
@@ -471,12 +505,12 @@ import { duplicateCheck } from '@/api/api'
this.$refs.departWindow.add(this.checkedDepartKeys,this.userId);
},
identityChange(e){
if(e.target.value==="1"){
if(e.target.value===1){
this.departIdShow=false;
}else{
this.departIdShow=true;
}
}
},
}
}
</script>
+2 -3
View File
@@ -184,7 +184,7 @@
import { ACCESS_TOKEN ,ENCRYPTED_STRING} from "@/store/mutation-types"
import { putAction,postAction,getAction } from '@/api/manage'
import { USER_INFO } from "@/store/mutation-types"
import {getRSAPublicKey} from '@/api/login.js'
import { getRSAPublicKey } from '@/utils/encryption.js'
const Base64 = require('js-base64').Base64
import {JSEncrypt} from 'jsencrypt'
@@ -225,7 +225,7 @@
Vue.ls.remove(ACCESS_TOKEN)
this.getRouterData();
this.handleChangeCheckCode();
this.getPublicKey(); //获取秘钥
},
methods: {
...mapActions(['Login', 'Logout', 'PhoneLogin']),
@@ -323,7 +323,6 @@
}).catch(()=>{
this.requestCodeSuccess=false
})
this.getPublicKey();
},
//获取RSA公钥
getPublicKey(){