diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml
index 12528e327..ee5a1b462 100644
--- a/yudao-dependencies/pom.xml
+++ b/yudao-dependencies/pom.xml
@@ -49,7 +49,6 @@
6.7.2
- 3.0.4
1.18.24
1.5.3.Final
5.8.9
@@ -449,12 +448,6 @@
${revision}
-
- com.github.ulisesbocchio
- jasypt-spring-boot-starter
- ${jasypt-spring-boot-starter.version}
-
-
cn.iocoder.cloud
yudao-spring-boot-starter-excel
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/EncryptTypeHandler.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/EncryptTypeHandler.java
index f5d5a8fd1..9327ebbfe 100644
--- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/EncryptTypeHandler.java
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/type/EncryptTypeHandler.java
@@ -1,10 +1,11 @@
package cn.iocoder.yudao.framework.mybatis.core.type;
import cn.hutool.core.lang.Assert;
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.symmetric.AES;
import cn.hutool.extra.spring.SpringUtil;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
-import org.jasypt.encryption.StringEncryptor;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
@@ -12,18 +13,20 @@ import java.sql.ResultSet;
import java.sql.SQLException;
/**
- * 字段字段的 TypeHandler 实现类,基于 {@link StringEncryptor} 实现
+ * 字段字段的 TypeHandler 实现类,基于 {@link AES} 实现
* 可通过 jasypt.encryptor.password 配置项,设置密钥
*
* @author 芋道源码
*/
public class EncryptTypeHandler extends BaseTypeHandler {
- private static StringEncryptor encryptor;
+ private static final String ENCRYPTOR_PROPERTY_NAME = "mybatis-plus.encryptor.password";
+
+ private static AES aes;
@Override
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) throws SQLException {
- ps.setString(i, getEncryptor().encrypt(parameter));
+ ps.setString(i, encrypt(parameter));
}
@Override
@@ -48,23 +51,25 @@ public class EncryptTypeHandler extends BaseTypeHandler {
if (value == null) {
return null;
}
- return getEncryptor().decrypt(value);
+ return getEncryptor().decryptStr(value);
}
public static String encrypt(String rawValue) {
if (rawValue == null) {
return null;
}
- return getEncryptor().encrypt(rawValue);
+ return getEncryptor().encryptBase64(rawValue);
}
- private static StringEncryptor getEncryptor() {
- if (encryptor != null) {
- return encryptor;
+ private static AES getEncryptor() {
+ if (aes != null) {
+ return aes;
}
- encryptor = SpringUtil.getBean(StringEncryptor.class);
- Assert.notNull(encryptor, "StringEncryptor 不能为空");
- return encryptor;
+ // 构建 AES
+ String password = SpringUtil.getProperty(ENCRYPTOR_PROPERTY_NAME);
+ Assert.notEmpty(password, "配置项({}) 不能为空", ENCRYPTOR_PROPERTY_NAME);
+ aes = SecureUtil.aes(password.getBytes());
+ return aes;
}
}
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-dev.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-dev.yaml
index f10e5167e..c49164280 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-dev.yaml
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-dev.yaml
@@ -58,10 +58,6 @@ spring:
database: 1 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud:
diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml
index 2f645bb17..1e5a4ac43 100644
--- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml
+++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application-local.yaml
@@ -68,10 +68,6 @@ spring:
database: 0 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud:
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml
index a75288fc5..56e8d8ee4 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml
@@ -58,10 +58,6 @@ spring:
database: 1 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud:
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml
index 70d12a8be..bc3cf1cf0 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-local.yaml
@@ -69,10 +69,6 @@ spring:
database: 0 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud:
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml
index 37977e898..5d6657b62 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml
@@ -40,6 +40,8 @@ mybatis-plus:
logic-delete-value: 1 # 逻辑已删除值(默认为 1)
logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
type-aliases-package: ${yudao.info.base-package}.dal.dataobject
+ encryptor:
+ password: XDV71a+xqStEA3WH # 加解密的秘钥,可使用 https://www.imaegoo.com/2020/aes-key-generator/ 网站生成
--- #################### RPC 远程调用相关配置 ####################
dubbo:
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap-local.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap-local.yaml
index d975b00c7..37204cde8 100644
--- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap-local.yaml
+++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/bootstrap-local.yaml
@@ -21,8 +21,3 @@ spring:
group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
file-extension: yaml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties
-
-# jasypt 禁止 Spring Cloud 的 bootstrap 阶段的启动,解决 https://github.com/ulisesbocchio/jasypt-spring-boot/issues/256 问题
-jasypt:
- encryptor:
- bootstrap: false
diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
index c23edf537..e1c997f7b 100755
--- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
+++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImplTest.java
@@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.infra.service.db;
import cn.hutool.core.util.ReflectUtil;
+import cn.hutool.crypto.symmetric.AES;
import cn.iocoder.yudao.framework.mybatis.core.type.EncryptTypeHandler;
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
@@ -9,7 +10,6 @@ import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigUpda
import cn.iocoder.yudao.module.infra.dal.dataobject.db.DataSourceConfigDO;
import cn.iocoder.yudao.module.infra.dal.mysql.db.DataSourceConfigMapper;
import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceProperties;
-import org.jasypt.encryption.StringEncryptor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
@@ -24,7 +24,8 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServic
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.module.infra.enums.ErrorCodeConstants.DATA_SOURCE_CONFIG_NOT_EXISTS;
-import static org.junit.jupiter.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mockStatic;
@@ -45,7 +46,7 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest {
private DataSourceConfigMapper dataSourceConfigMapper;
@MockBean
- private StringEncryptor stringEncryptor;
+ private AES aes;
@MockBean
private DynamicDataSourceProperties dynamicDataSourceProperties;
@@ -53,9 +54,9 @@ public class DataSourceConfigServiceImplTest extends BaseDbUnitTest {
@BeforeEach
public void setUp() {
// mock 一个空实现的 StringEncryptor,避免 EncryptTypeHandler 报错
- ReflectUtil.setFieldValue(EncryptTypeHandler.class, "encryptor", stringEncryptor);
- when(stringEncryptor.encrypt(anyString())).then((Answer) invocation -> invocation.getArgument(0));
- when(stringEncryptor.decrypt(anyString())).then((Answer) invocation -> invocation.getArgument(0));
+ ReflectUtil.setFieldValue(EncryptTypeHandler.class, "aes", aes);
+ when(aes.encryptBase64(anyString())).then((Answer) invocation -> invocation.getArgument(0));
+ when(aes.decryptStr(anyString())).then((Answer) invocation -> invocation.getArgument(0));
}
@Test
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
index 7873a0d66..d1352e047 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-dev.yaml
@@ -58,10 +58,6 @@ spring:
database: 1 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud:
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
index ed91a9187..c70a00774 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
+++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application-local.yaml
@@ -68,10 +68,6 @@ spring:
database: 0 # 数据库索引
# password: 123456 # 密码,建议生产环境开启
-jasypt:
- encryptor:
- password: yuanma # 加解密的秘钥
-
--- #################### MQ 消息队列相关配置 ####################
spring:
cloud: