加密数据
This commit is contained in:
parent
70f24c79ba
commit
c26034a6ce
|
@ -24,6 +24,11 @@
|
|||
<artifactId>jeecg-module-demo</artifactId>
|
||||
<version>${jeecgboot.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
<!--人大金仓
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework</groupId>
|
||||
|
|
|
@ -48,6 +48,7 @@ public class CeesLocalTeacherServiceImpl extends ServiceImpl<CeesLocalTeacherMap
|
|||
LambdaQueryWrapper<CeesUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CeesUser::getUserId, ceesLocalTeacher.getUserId());
|
||||
CeesUser user = ceesUserMapper.selectOne(queryWrapper);
|
||||
if(user.getOpenId() == null) {
|
||||
ceesLocalTeacher.setGroupId(user.getGroupId());
|
||||
ceesLocalTeacher.setMajorId(user.getMajorId());
|
||||
ceesLocalTeacher.setUserMajorId(user.getUserMajorId());
|
||||
|
@ -65,6 +66,9 @@ public class CeesLocalTeacherServiceImpl extends ServiceImpl<CeesLocalTeacherMap
|
|||
jsonObject.put("user", ceesLocalTeacher);
|
||||
jsonObject.put("router", "/mainPage");
|
||||
return Result.ok(jsonObject);
|
||||
}else {
|
||||
return Result.ok("当前账号以绑定其他微信,如有疑问请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,9 @@ import org.jeecg.modules.enums.identity.MajorLetterEnum;
|
|||
import org.jeecg.modules.enums.identity.StudentLetterEnum;
|
||||
import org.jeecg.modules.mapper.*;
|
||||
import org.jeecg.modules.service.ICeesUserService;
|
||||
import org.jeecg.modules.utils.JasyptUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -50,6 +52,9 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
|||
@Resource
|
||||
CeesH5TimeMapper ceesH5TimeMapper;
|
||||
|
||||
@Value("${jasypt.encryptor.password}")
|
||||
private String passWord;
|
||||
|
||||
/**
|
||||
* @param ceesUser
|
||||
* @return {@link String }
|
||||
|
@ -272,6 +277,9 @@ public class CeesUserServiceImpl extends ServiceImpl<CeesUserMapper, CeesUser> i
|
|||
LambdaQueryWrapper<CeesWaiTeacher> ceesWaiTeacherLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
ceesWaiTeacherLambdaQueryWrapper.eq(CeesWaiTeacher::getUserId, userId);
|
||||
CeesWaiTeacher ceesWaiTeacher = ceesWaiTeacherMapper.selectOne(ceesWaiTeacherLambdaQueryWrapper);
|
||||
//解密
|
||||
ceesWaiTeacher.setIdentityId(JasyptUtil.decrypt(ceesWaiTeacher.getIdentityId(), passWord));
|
||||
ceesWaiTeacher.setPyCard(JasyptUtil.decrypt(ceesWaiTeacher.getPyCard(), passWord));
|
||||
if (ceesWaiTeacher != null) {
|
||||
jsonObject.put("user", ceesWaiTeacher);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.tomcat.Jar;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
|
@ -26,6 +27,8 @@ import org.jeecg.modules.system.entity.SysRole;
|
|||
import org.jeecg.modules.system.entity.SysUserRole;
|
||||
import org.jeecg.modules.system.mapper.SysRoleMapper;
|
||||
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
|
||||
import org.jeecg.modules.utils.JasyptUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -56,6 +59,9 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
|||
@Resource
|
||||
SysUserRoleMapper sysUserRoleMapper;
|
||||
|
||||
@Value("${jasypt.encryptor.password}")
|
||||
private String passWord;
|
||||
|
||||
@Override
|
||||
public Result updateDormitory(String id, String dormitoryId) {
|
||||
LambdaQueryWrapper<CeesWaiTeacher> wrapper = new LambdaQueryWrapper();
|
||||
|
@ -169,10 +175,16 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
|||
LambdaQueryWrapper<CeesUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CeesUser::getUserId, ceesWaiTeacher.getUserId());
|
||||
CeesUser ceesUser = ceesUserMapper.selectOne(queryWrapper);
|
||||
if(ceesUser.getOpenId() != null) {
|
||||
ceesWaiTeacher.setGroupId(ceesUser.getGroupId());
|
||||
ceesWaiTeacher.setMajorId(ceesUser.getMajorId());
|
||||
ceesWaiTeacher.setUserMajorId(ceesUser.getUserMajorId());
|
||||
ceesWaiTeacher.setOpenId(ceesWaiTeacher.getOpenId());
|
||||
|
||||
//加密
|
||||
ceesWaiTeacher.setPyCard(JasyptUtil.encrypt(ceesWaiTeacher.getPyCard(),passWord));
|
||||
ceesWaiTeacher.setIdentityId((JasyptUtil.encrypt(ceesWaiTeacher.getIdentityId(),passWord)));
|
||||
|
||||
this.save(ceesWaiTeacher);
|
||||
ceesUser.setUserName(ceesWaiTeacher.getUserName());
|
||||
ceesUser.setOpenId(ceesWaiTeacher.getOpenId());
|
||||
|
@ -187,6 +199,9 @@ public class CeesWaiTeacherServiceImpl extends ServiceImpl<CeesWaiTeacherMapper,
|
|||
jsonObject.put("user", ceesWaiTeacher);
|
||||
jsonObject.put("router", "/mainPage");
|
||||
return Result.ok(jsonObject);
|
||||
}else {
|
||||
return Result.ok("当前账号以绑定其他微信,如有疑问请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -47,6 +47,7 @@ public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> impl
|
|||
LambdaQueryWrapper<CeesUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(CeesUser::getUserId, student.getUserId());
|
||||
CeesUser user = ceesUserMapper.selectOne(queryWrapper);
|
||||
if(user.getOpenId() == null) {
|
||||
student.setGroupId(user.getGroupId());
|
||||
student.setMajorId(user.getMajorId());
|
||||
student.setUserMajorId(user.getUserMajorId());
|
||||
|
@ -62,6 +63,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> impl
|
|||
jsonObject.put("user", student);
|
||||
jsonObject.put("router", "/mainPage");
|
||||
return Result.ok(jsonObject);
|
||||
}else{
|
||||
return Result.ok("当前账号以绑定其他微信,如有疑问请联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package org.jeecg.modules.utils;
|
||||
|
||||
|
||||
import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
|
||||
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
|
||||
|
||||
public class JasyptUtil {
|
||||
|
||||
/**
|
||||
* PBE 算法
|
||||
*/
|
||||
public static final String PBE_ALGORITHMS_MD5_DES = "PBEWITHMD5ANDDES";
|
||||
public static final String PBE_ALGORITHMS_MD5_TRIPLEDES = "PBEWITHMD5ANDTRIPLEDES";
|
||||
public static final String PBE_ALGORITHMS_SHA1_DESEDE = "PBEWITHSHA1ANDDESEDE";
|
||||
public static final String PBE_ALGORITHMS_SHA1_RC2_40 = "PBEWITHSHA1ANDRC2_40";
|
||||
|
||||
private JasyptUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Jasypt 加密
|
||||
*
|
||||
* @param encryptedStr 加密字符串
|
||||
* @param password 盐值
|
||||
* @return
|
||||
*/
|
||||
public static String encrypt(String encryptedStr, String password) {
|
||||
return encrypt(encryptedStr, PBE_ALGORITHMS_MD5_DES, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jasypt 加密
|
||||
*
|
||||
* @param encryptedStr 加密字符串
|
||||
* @param algorithm 加密算法
|
||||
* PBE ALGORITHMS: [PBEWITHMD5ANDDES, PBEWITHMD5ANDTRIPLEDES, PBEWITHSHA1ANDDESEDE, PBEWITHSHA1ANDRC2_40]
|
||||
* @param password 盐值
|
||||
* @return
|
||||
*/
|
||||
public static String encrypt(String encryptedStr, String algorithm, String password) {
|
||||
// StandardPBEStringEncryptor、StandardPBEBigDecimalEncryptor、StandardPBEBigIntegerEncryptor、StandardPBEByteEncryptor
|
||||
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
|
||||
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
|
||||
|
||||
// 指定加密算法
|
||||
config.setAlgorithm(algorithm);
|
||||
// 加密盐值
|
||||
config.setPassword(password);
|
||||
//config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator");
|
||||
encryptor.setConfig(config);
|
||||
|
||||
// 加密
|
||||
return encryptor.encrypt(encryptedStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jasypt 解密
|
||||
*
|
||||
* @param decryptStr 解密字符串
|
||||
* @param password 盐值
|
||||
* @return
|
||||
*/
|
||||
public static String decrypt(String decryptStr, String password) {
|
||||
return decrypt(decryptStr, PBE_ALGORITHMS_MD5_DES, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Jasypt 解密
|
||||
*
|
||||
* @param decryptStr 解密字符串
|
||||
* @param algorithm 指定解密算法:解密算法要与加密算法一一对应
|
||||
* PBE ALGORITHMS: [PBEWITHMD5ANDDES, PBEWITHMD5ANDTRIPLEDES, PBEWITHSHA1ANDDESEDE, PBEWITHSHA1ANDRC2_40]
|
||||
* @param password 盐值
|
||||
* @return
|
||||
*/
|
||||
public static String decrypt(String decryptStr, String algorithm, String password) {
|
||||
// StandardPBEStringEncryptor、StandardPBEBigDecimalEncryptor、StandardPBEBigIntegerEncryptor、StandardPBEByteEncryptor
|
||||
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
|
||||
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
|
||||
|
||||
// 指定解密算法:解密算法要与加密算法一一对应
|
||||
config.setAlgorithm(algorithm);
|
||||
// 加密秘钥
|
||||
config.setPassword(password);
|
||||
//config.setIvGeneratorClassName("org.jasypt.iv.NoIvGenerator");
|
||||
encryptor.setConfig(config);
|
||||
|
||||
// 解密
|
||||
return encryptor.decrypt(decryptStr);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String encryptedStr = "I am the string to be encrypted";
|
||||
String algorithm = PBE_ALGORITHMS_SHA1_RC2_40;
|
||||
String password = "salt";
|
||||
|
||||
String str = JasyptUtil.encrypt(encryptedStr, algorithm, password);
|
||||
System.out.println("加密后的字符串:" + str);
|
||||
System.out.println("解密后的字符串:" + JasyptUtil.decrypt(str, algorithm, password));
|
||||
}
|
||||
}
|
|
@ -19,3 +19,20 @@ wx:
|
|||
# apiUrl: https://api.weixin.qq.com/
|
||||
# openApiUrl: https://open.weixin.qq.com/
|
||||
# authRedirectUri: https://6072-112-102-213-17.ngrok-free.app/home
|
||||
|
||||
|
||||
|
||||
jasypt:
|
||||
encryptor:
|
||||
# 盐值
|
||||
password: bigdata
|
||||
# 指定加密方式
|
||||
algorithm: PBEWithMD5AndDES
|
||||
iv-generator-classname: org.jasypt.iv.NoIvGenerator
|
||||
property:
|
||||
# 标识为加密属性的前缀
|
||||
prefix: ENC(
|
||||
# 标识为加密属性的后缀
|
||||
suffix: )
|
||||
|
||||
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -422,6 +422,12 @@
|
|||
<artifactId>flyway-core</artifactId>
|
||||
<version>7.15.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
<version>3.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
Loading…
Reference in New Issue