From 68131e3c9c7164451d40a5cc233477e70ae5a68a Mon Sep 17 00:00:00 2001
From: song_jx <1649991905@qq.com>
Date: Sat, 4 Sep 2021 18:06:19 +0800
Subject: [PATCH 1/5] =?UTF-8?q?[=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD](mast?=
=?UTF-8?q?er):=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E6=B3=A8=E8=A7=A3=E8=A7=A3?=
=?UTF-8?q?=E5=AF=86=E5=8F=8A=E8=84=B1=E6=95=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../annotation/DecryptTransaction.java | 36 ++++++
.../encrypt/annotation/SensitiveData.java | 15 +++
.../encrypt/plugins/DecryptInterceptor.java | 103 ++++++++++++++++++
.../mybatis/encrypt/util/DecryptUtil.java | 59 ++++++++++
4 files changed, 213 insertions(+)
create mode 100644 src/main/java/org/dflish/mybatis/encrypt/annotation/DecryptTransaction.java
create mode 100644 src/main/java/org/dflish/mybatis/encrypt/annotation/SensitiveData.java
create mode 100644 src/main/java/org/dflish/mybatis/encrypt/plugins/DecryptInterceptor.java
create mode 100644 src/main/java/org/dflish/mybatis/encrypt/util/DecryptUtil.java
diff --git a/src/main/java/org/dflish/mybatis/encrypt/annotation/DecryptTransaction.java b/src/main/java/org/dflish/mybatis/encrypt/annotation/DecryptTransaction.java
new file mode 100644
index 0000000..b5993d0
--- /dev/null
+++ b/src/main/java/org/dflish/mybatis/encrypt/annotation/DecryptTransaction.java
@@ -0,0 +1,36 @@
+package org.dflish.mybatis.encrypt.annotation;
+
+import org.dflish.mybatis.encrypt.util.DesensitizedType;
+
+import java.lang.annotation.*;
+
+
+/**
+ * 解密注解
+ *
+ * @author song_jx
+ * @date 2021-09-04 03:42:44
+ */
+@Documented
+@Inherited
+@Target({ElementType.FIELD})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DecryptTransaction {
+
+ /**
+ * 数据是否需要脱敏,默认不脱敏
+ *
+ * @return @return boolean
+ * @author song_jx
+ */
+ boolean isDesensitized() default false;
+
+ /**
+ * 数据脱敏类型,默认手机号脱敏
+ *
+ * @return @return {@link DesensitizedType }
+ * @author song_jx
+ */
+ DesensitizedType desensitizedType() default DesensitizedType.MOBILE_PHONE;
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/dflish/mybatis/encrypt/annotation/SensitiveData.java b/src/main/java/org/dflish/mybatis/encrypt/annotation/SensitiveData.java
new file mode 100644
index 0000000..a4ed5f1
--- /dev/null
+++ b/src/main/java/org/dflish/mybatis/encrypt/annotation/SensitiveData.java
@@ -0,0 +1,15 @@
+package org.dflish.mybatis.encrypt.annotation;
+
+import java.lang.annotation.*;
+
+/**
+ * 敏感数据
+ *
+ * @author song_jx
+ * @date 2021-09-04 03:56:30
+ */
+@Inherited
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface SensitiveData {
+}
\ No newline at end of file
diff --git a/src/main/java/org/dflish/mybatis/encrypt/plugins/DecryptInterceptor.java b/src/main/java/org/dflish/mybatis/encrypt/plugins/DecryptInterceptor.java
new file mode 100644
index 0000000..b79f929
--- /dev/null
+++ b/src/main/java/org/dflish/mybatis/encrypt/plugins/DecryptInterceptor.java
@@ -0,0 +1,103 @@
+package org.dflish.mybatis.encrypt.plugins;
+
+import cn.hutool.core.annotation.AnnotationUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import org.apache.ibatis.executor.resultset.ResultSetHandler;
+import org.apache.ibatis.plugin.*;
+import org.apache.ibatis.reflection.MetaObject;
+import org.apache.ibatis.reflection.SystemMetaObject;
+import org.dflish.mybatis.encrypt.annotation.SensitiveData;
+import org.dflish.mybatis.encrypt.properties.EnCryptProperties;
+import org.dflish.mybatis.encrypt.util.DecryptUtil;
+
+import java.lang.reflect.Proxy;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * 解密拦截器
+ *
+ * @author song_jx
+ * @date 2021-09-04 03:28:50
+ */
+@Intercepts({
+ @Signature(type = ResultSetHandler.class, method = "handleResultSets", args = {Statement.class})
+})
+public class DecryptInterceptor implements Interceptor {
+
+ private static final Log log = LogFactory.get();
+
+ private final EnCryptProperties properties;
+
+ public DecryptInterceptor(EnCryptProperties properties) {
+ this.properties = properties;
+ }
+
+ @Override
+ public Object intercept(Invocation invocation) throws Throwable {
+ // 取出查询的结果
+ Object resultObject = invocation.proceed();
+
+ if (ObjectUtil.isNull(resultObject)) {
+ return null;
+ }
+
+ if (resultObject instanceof ArrayList) {
+ // 基于selectList
+ List resultList = (ArrayList) resultObject;
+ if (CollUtil.isNotEmpty(resultList) && isNeedDecrypt(resultList.get(0))) {
+ for (Object result : resultList) {
+ //逐一解密
+ DecryptUtil.decrypt(result, properties.getKey());
+ }
+ }
+ } else {
+ // 基于selectOne
+ if (isNeedDecrypt(resultObject)) {
+ DecryptUtil.decrypt(resultObject, properties.getKey());
+ }
+ }
+
+ return resultObject;
+ }
+
+ @Override
+ public Object plugin(Object target) {
+ return Plugin.wrap(target, this);
+ }
+
+ @Override
+ public void setProperties(Properties properties) {
+
+ }
+
+ /**
+ *
+ * 获得真正的处理对象,可能多层代理.
+ *
+ */
+ private Object realTarget(Object target) {
+ if (Proxy.isProxyClass(target.getClass())) {
+ MetaObject metaObject = SystemMetaObject.forObject(target);
+ return realTarget(metaObject.getValue("h.target"));
+ }
+ return target;
+ }
+
+ /**
+ * 是否需要解密
+ *
+ * @param object 对象
+ * @return @return boolean
+ * @author song_jx
+ */
+ private boolean isNeedDecrypt(Object object) {
+ return AnnotationUtil.hasAnnotation(object.getClass(), SensitiveData.class);
+ }
+
+}
diff --git a/src/main/java/org/dflish/mybatis/encrypt/util/DecryptUtil.java b/src/main/java/org/dflish/mybatis/encrypt/util/DecryptUtil.java
new file mode 100644
index 0000000..3b2afd7
--- /dev/null
+++ b/src/main/java/org/dflish/mybatis/encrypt/util/DecryptUtil.java
@@ -0,0 +1,59 @@
+package org.dflish.mybatis.encrypt.util;
+
+import cn.hutool.core.annotation.AnnotationUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.ReflectUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import org.dflish.mybatis.encrypt.annotation.DecryptTransaction;
+
+import java.lang.reflect.Field;
+
+/**
+ * 解密工具类
+ *
+ * @author song_jx
+ * @date 2021-09-04 04:13:13
+ */
+public class DecryptUtil {
+
+ private static final Log log = LogFactory.get();
+
+ /**
+ * 解密
+ *
+ * @param result 结果
+ * @param key 关键
+ * @return @return {@link T }
+ * @author song_jx
+ */
+ public static T decrypt(T result, String key) {
+ try {
+ // 取出resultType的类
+ Field[] declaredFields = ReflectUtil.getFields(result.getClass());
+ for (Field field : declaredFields) {
+ // 取出所有被DecryptTransaction注解的字段
+ DecryptTransaction annotation = AnnotationUtil.getAnnotation(field, DecryptTransaction.class);
+ if (ObjectUtil.isNotNull(annotation)) {
+ Object fieldValue = ReflectUtil.getFieldValue(result, field);
+ // String的解密
+ if (fieldValue instanceof String) {
+ String value = (String) fieldValue;
+ value = AesUtils.decrypt(value, key);
+
+ // 数据脱敏
+ if (annotation.isDesensitized()) {
+ value = DesensitizedExecutor.desensitized(annotation.desensitizedType(), value);
+ }
+
+ field.set(result, value);
+ }
+ }
+ }
+ } catch (Exception e) {
+ log.error("---> [Mybatis 解密拦截器] 字段注解 解密异常...", e);
+ }
+ return result;
+ }
+
+}
--
Gitee
From db9405ac7da1887b9cc33ea4bd62c9888c7edd47 Mon Sep 17 00:00:00 2001
From: song_jx <1649991905@qq.com>
Date: Sat, 4 Sep 2021 18:07:23 +0800
Subject: [PATCH 2/5] =?UTF-8?q?[=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD](mast?=
=?UTF-8?q?er):=20=E5=AE=9E=E4=BD=93=E7=B1=BB=E6=B3=A8=E8=A7=A3=E8=A7=A3?=
=?UTF-8?q?=E5=AF=86=E5=8F=8A=E8=84=B1=E6=95=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../encrypt/config/MybatisEncryptAutoConfigure.java | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/dflish/mybatis/encrypt/config/MybatisEncryptAutoConfigure.java b/src/main/java/org/dflish/mybatis/encrypt/config/MybatisEncryptAutoConfigure.java
index 2ac9ddb..280cc41 100644
--- a/src/main/java/org/dflish/mybatis/encrypt/config/MybatisEncryptAutoConfigure.java
+++ b/src/main/java/org/dflish/mybatis/encrypt/config/MybatisEncryptAutoConfigure.java
@@ -1,7 +1,8 @@
package org.dflish.mybatis.encrypt.config;
import lombok.AllArgsConstructor;
-import org.dflish.mybatis.encrypt.plugins.EnCryptInterceptor;
+import org.dflish.mybatis.encrypt.plugins.DecryptInterceptor;
+import org.dflish.mybatis.encrypt.plugins.EncryptInterceptor;
import org.dflish.mybatis.encrypt.properties.EnCryptProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -22,7 +23,13 @@ public class MybatisEncryptAutoConfigure {
private final EnCryptProperties enCryptProperties;
@Bean
- public EnCryptInterceptor enCryptInterceptor() {
- return new EnCryptInterceptor(enCryptProperties);
+ public EncryptInterceptor enCryptInterceptor() {
+ return new EncryptInterceptor(enCryptProperties);
}
+
+ @Bean
+ public DecryptInterceptor decryptInterceptor() {
+ return new DecryptInterceptor(enCryptProperties);
+ }
+
}
--
Gitee
From ef8a4120a1d796e3ffef079db0161c1e90704463 Mon Sep 17 00:00:00 2001
From: song_jx <1649991905@qq.com>
Date: Sat, 4 Sep 2021 18:09:35 +0800
Subject: [PATCH 3/5] =?UTF-8?q?[Bug=E4=BF=AE=E5=A4=8D](master):=20?=
=?UTF-8?q?=E4=BF=AE=E5=A4=8Dsql=E6=9F=A5=E8=AF=A2=E5=B8=A6=E6=9C=89=201?=
=?UTF-8?q?=3D1=20=E6=97=B6=EF=BC=8CleftExpression=E5=BC=BA=E8=BD=AC?=
=?UTF-8?q?=E4=B8=BAColumn=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=BC=82=E5=B8=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../encrypt/core/CCJSQLStatementContext.java | 53 +++++++++++++------
1 file changed, 36 insertions(+), 17 deletions(-)
diff --git a/src/main/java/org/dflish/mybatis/encrypt/core/CCJSQLStatementContext.java b/src/main/java/org/dflish/mybatis/encrypt/core/CCJSQLStatementContext.java
index 31ead5a..80a5730 100644
--- a/src/main/java/org/dflish/mybatis/encrypt/core/CCJSQLStatementContext.java
+++ b/src/main/java/org/dflish/mybatis/encrypt/core/CCJSQLStatementContext.java
@@ -2,10 +2,13 @@ package org.dflish.mybatis.encrypt.core;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
import lombok.Data;
import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.JdbcParameter;
+import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
@@ -27,6 +30,8 @@ import java.util.*;
@Data
public class CCJSQLStatementContext {
+ private static final Log log = LogFactory.get();
+
private Statement statements;
private List tableList;
@@ -112,24 +117,38 @@ public class CCJSQLStatementContext {
PlainSelect plain = (PlainSelect) select.getSelectBody();
Expression where = plain.getWhere();
- where.accept(new ExpressionDeParser(null, b) {
- @Override
- public void visit(EqualsTo equalsTo) {
- Column leftExpression = (Column) equalsTo.getLeftExpression();
-
- Expression rightExpression = equalsTo.getRightExpression();
-
- if (rightExpression instanceof JdbcParameter){
- JdbcParameter jdbcParameter = (JdbcParameter) rightExpression;
- Integer index = jdbcParameter.getIndex();
- CCJSQLCryptExpressionDTO dto = new CCJSQLCryptExpressionDTO();
- dto.setAlias(TablesNamesFinderPlus.getAlias(leftExpression.getTable()));
- dto.setColumnName(leftExpression.getColumnName());
- dto.setIndex(index);
- list.add(dto);
+ if (null != where) {
+ where.accept(new ExpressionDeParser(null, b) {
+ @Override
+ public void visit(EqualsTo equalsTo) {
+ Expression leftExp = equalsTo.getLeftExpression();
+ // 判断 1 = 1 情况
+ boolean isLongValue = leftExp instanceof LongValue;
+ Column leftExpression = null;
+ if (!isLongValue) {
+ leftExpression = (Column) leftExp;
+ }
+
+ Expression rightExpression = equalsTo.getRightExpression();
+ if (null != leftExpression && rightExpression instanceof JdbcParameter) {
+ JdbcParameter jdbcParameter = (JdbcParameter) rightExpression;
+ Integer index = jdbcParameter.getIndex();
+ CCJSQLCryptExpressionDTO dto = new CCJSQLCryptExpressionDTO();
+ String alias = TablesNamesFinderPlus.getAlias(leftExpression.getTable());
+ if (StrUtil.isBlank(alias)) {
+ log.error("---> [Mybatis 加密拦截器] 字段 {} 未设置归属表别名,默认使用 t 做为字段归属表的别名...",
+ leftExpression.getColumnName());
+ dto.setAlias("t");
+ } else {
+ dto.setAlias(alias);
+ }
+ dto.setColumnName(leftExpression.getColumnName());
+ dto.setIndex(index);
+ list.add(dto);
+ }
}
- }
- });
+ });
+ }
return list;
}
--
Gitee
From d6c044d36f473f745ec56ab5c0bfeb1300bc956a Mon Sep 17 00:00:00 2001
From: song_jx <1649991905@qq.com>
Date: Sat, 4 Sep 2021 18:11:46 +0800
Subject: [PATCH 4/5] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84](mast?=
=?UTF-8?q?er):=20AES=E5=8A=A0=E5=AF=86=E5=B7=A5=E5=85=B7=E7=B1=BB?=
=?UTF-8?q?=E6=9B=BF=E6=8D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
切换为java mysql 通用aes加密算法,在数据库中可使用如下语句查询
```
SELECT
AES_DECRYPT(UNHEX(school_db_host), 'coco') FROM base_info;
```
---
...terceptor.java => EncryptInterceptor.java} | 48 +++++++---
.../mybatis/encrypt/rule/EncryptRule.java | 13 +--
.../dflish/mybatis/encrypt/util/AesUtils.java | 90 +++++++++++++++++++
3 files changed, 129 insertions(+), 22 deletions(-)
rename src/main/java/org/dflish/mybatis/encrypt/plugins/{EnCryptInterceptor.java => EncryptInterceptor.java} (59%)
create mode 100644 src/main/java/org/dflish/mybatis/encrypt/util/AesUtils.java
diff --git a/src/main/java/org/dflish/mybatis/encrypt/plugins/EnCryptInterceptor.java b/src/main/java/org/dflish/mybatis/encrypt/plugins/EncryptInterceptor.java
similarity index 59%
rename from src/main/java/org/dflish/mybatis/encrypt/plugins/EnCryptInterceptor.java
rename to src/main/java/org/dflish/mybatis/encrypt/plugins/EncryptInterceptor.java
index cf55ce6..18b6882 100644
--- a/src/main/java/org/dflish/mybatis/encrypt/plugins/EnCryptInterceptor.java
+++ b/src/main/java/org/dflish/mybatis/encrypt/plugins/EncryptInterceptor.java
@@ -1,41 +1,43 @@
package org.dflish.mybatis.encrypt.plugins;
-import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
-import lombok.extern.slf4j.Slf4j;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
import org.apache.ibatis.executor.statement.StatementHandler;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
-import org.apache.ibatis.plugin.Interceptor;
-import org.apache.ibatis.plugin.Intercepts;
-import org.apache.ibatis.plugin.Invocation;
-import org.apache.ibatis.plugin.Signature;
+import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.dflish.mybatis.encrypt.properties.EnCryptProperties;
import org.dflish.mybatis.encrypt.rewrite.EncryptPreParameterRewriter;
+import java.lang.reflect.Proxy;
import java.sql.Statement;
import java.util.List;
+import java.util.Properties;
/**
+ * 加密拦截器
+ *
* @author liangwx
+ * @date 2021-09-04 03:28:58
*/
-@Slf4j
@Intercepts({
@Signature(type = StatementHandler.class, method = "parameterize", args = Statement.class)
})
-public class EnCryptInterceptor implements Interceptor {
+public class EncryptInterceptor implements Interceptor {
+
+ private static final Log log = LogFactory.get();
private final EncryptPreParameterRewriter rewriter;
- public EnCryptInterceptor(EnCryptProperties properties) {
+ public EncryptInterceptor(EnCryptProperties properties) {
this.rewriter = new EncryptPreParameterRewriter(properties);
}
@Override
public Object intercept(Invocation invocation) throws Throwable {
-
- Object target = PluginUtils.realTarget(invocation.getTarget());
+ Object target = realTarget(invocation.getTarget());
MetaObject metaObject = SystemMetaObject.forObject(target);
MappedStatement ms = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
@@ -49,4 +51,28 @@ public class EnCryptInterceptor implements Interceptor {
return returnObj;
}
+
+ @Override
+ public Object plugin(Object target) {
+ return Plugin.wrap(target, this);
+ }
+
+ @Override
+ public void setProperties(Properties properties) {
+
+ }
+
+ /**
+ *
+ * 获得真正的处理对象,可能多层代理.
+ *
+ */
+ private Object realTarget(Object target) {
+ if (Proxy.isProxyClass(target.getClass())) {
+ MetaObject metaObject = SystemMetaObject.forObject(target);
+ return realTarget(metaObject.getValue("h.target"));
+ }
+ return target;
+ }
+
}
diff --git a/src/main/java/org/dflish/mybatis/encrypt/rule/EncryptRule.java b/src/main/java/org/dflish/mybatis/encrypt/rule/EncryptRule.java
index cee0031..9d404d3 100644
--- a/src/main/java/org/dflish/mybatis/encrypt/rule/EncryptRule.java
+++ b/src/main/java/org/dflish/mybatis/encrypt/rule/EncryptRule.java
@@ -1,15 +1,12 @@
package org.dflish.mybatis.encrypt.rule;
-import cn.hutool.crypto.SecureUtil;
-import cn.hutool.crypto.symmetric.AES;
-import org.apache.commons.codec.digest.DigestUtils;
import org.dflish.mybatis.encrypt.properties.EnCryptProperties;
import org.dflish.mybatis.encrypt.properties.EncryptColumnRuleConfiguration;
import org.dflish.mybatis.encrypt.properties.EncryptTableRuleConfiguration;
+import org.dflish.mybatis.encrypt.util.AesUtils;
import org.dflish.mybatis.encrypt.util.DesensitizedExecutor;
import org.dflish.mybatis.encrypt.util.DesensitizedType;
-import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
@@ -24,16 +21,10 @@ public class EncryptRule {
private final String key;
- private final AES aes;
-
-
public EncryptRule(EnCryptProperties properties) {
this.properties = properties;
this.tables = properties.getTables();
this.key = properties.getKey();
-
- final byte[] bytes = Arrays.copyOf(DigestUtils.sha1(key), 16);
- aes = SecureUtil.aes(bytes);
}
public Optional getEncryptColumnRuleConfiguration(String tableName, String columnName){
@@ -73,7 +64,7 @@ public class EncryptRule {
final EncryptColumnRuleConfiguration configuration = encryptColumnRuleConfiguration.get();
if (configuration.getEncryptor()){
- return aes.encryptBase64((String) originalValues);
+ return AesUtils.encrypt((String) originalValues, key);
}
if (configuration.getDesensitized()){
diff --git a/src/main/java/org/dflish/mybatis/encrypt/util/AesUtils.java b/src/main/java/org/dflish/mybatis/encrypt/util/AesUtils.java
new file mode 100644
index 0000000..2d43c5c
--- /dev/null
+++ b/src/main/java/org/dflish/mybatis/encrypt/util/AesUtils.java
@@ -0,0 +1,90 @@
+package org.dflish.mybatis.encrypt.util;
+
+import cn.hutool.core.util.CharsetUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.log.Log;
+import cn.hutool.log.LogFactory;
+import org.apache.commons.codec.binary.Hex;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+
+/**
+ * aes工具类
+ *
+ * @author song_jx
+ * @date 2021-09-04 05:14:04
+ */
+public class AesUtils {
+
+ private static final Log log = LogFactory.get();
+
+ /**
+ * 算法
+ */
+ private static final String ALGORITHM = "AES";
+
+ /**
+ * 生成mysql的aes密钥
+ *
+ * @param key 密钥
+ * @param encoding 编码
+ * @return @return {@link SecretKeySpec }
+ * @author song_jx
+ */
+ public static SecretKeySpec generateMySQLAESKey(final String key, final String encoding) throws Exception {
+ final byte[] finalKey = new byte[16];
+ int i = 0;
+ for (byte b : key.getBytes(encoding)) {
+ finalKey[i++ % 16] ^= b;
+ }
+ return new SecretKeySpec(finalKey, ALGORITHM);
+ }
+
+ /**
+ * 解密
+ *
+ * @param data 数据
+ * @param key 密钥
+ * @return @return {@link String }
+ * @throws Exception 异常
+ * @author song_jx
+ */
+ public static String decrypt(String data, String key) {
+ String decryptStr = StrUtil.EMPTY;
+ try {
+ final Cipher decryptCipher = Cipher.getInstance(ALGORITHM);
+ decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(key, CharsetUtil.UTF_8));
+ decryptStr = new String(decryptCipher.doFinal(Hex.decodeHex(data.toCharArray())));
+ } catch (Exception e) {
+ log.error("--- [AES工具类] aes解密失败...", e);
+ }
+ return decryptStr;
+ }
+
+ /**
+ * 加密
+ *
+ * @param data 数据
+ * @param key 密钥
+ * @return @return {@link String }
+ * @author song_jx
+ */
+ public static String encrypt(String data, String key) {
+ String encryptStr = StrUtil.EMPTY;
+ try {
+ final Cipher encryptCipher = Cipher.getInstance(ALGORITHM);
+ encryptCipher.init(Cipher.ENCRYPT_MODE, generateMySQLAESKey(key, CharsetUtil.UTF_8));
+ char[] code = Hex.encodeHex(encryptCipher.doFinal(data.getBytes(CharsetUtil.UTF_8)));
+ StringBuilder builder = new StringBuilder();
+ for (char d : code) {
+ builder.append(d);
+ }
+ encryptStr = builder.toString();
+ } catch (Exception e) {
+ log.error("--- [AES工具类] aes加密失败...", e);
+ }
+ return encryptStr;
+ }
+
+}
\ No newline at end of file
--
Gitee
From c89dd41c8c05592e87297e4b9a200245cd46d9e9 Mon Sep 17 00:00:00 2001
From: song_jx <1649991905@qq.com>
Date: Sat, 4 Sep 2021 18:14:26 +0800
Subject: [PATCH 5/5] =?UTF-8?q?[=E7=BC=96=E8=AF=91=E4=BB=A3=E7=A0=81](mast?=
=?UTF-8?q?er):=20pom.xml=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
1. 剔除mybatis-plus
2. 降级spring-boot
---
.gitignore | 1 +
pom.xml | 140 +++++++++++++++++++++++++++++++----------------------
2 files changed, 84 insertions(+), 57 deletions(-)
diff --git a/.gitignore b/.gitignore
index 5d947ca..e7266ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ bin-release/
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
+/.idea/
diff --git a/pom.xml b/pom.xml
index 1657fd2..581a074 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,55 +6,37 @@
org.dflish
mybatis-encrypt-plugins
- 1.0-SNAPSHOT
+ 0.1-SNAPSHOT
1.8
1.8
UTF-8
- 8
+ 1.8
- 2.2.8.RELEASE
+ 2.1.18.RELEASE
5.4.2
-
- 3.3.1
-
+ 3.4.5
+ 3.1
-
-
-
- cn.hutool
- hutool-all
- ${hutool.version}
-
-
org.springframework.boot
spring-boot-dependencies
- ${spring-boot-dependencies.version}
+ ${spring-boot.version}
pom
import
-
-
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatis-plus-boot-starter.version}
-
-
-
mysql
mysql-connector-java
@@ -76,6 +58,11 @@
true
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
+
cn.hutool
@@ -89,45 +76,84 @@
test
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatis-plus-boot-starter.version}
+ com.github.jsqlparser
+ jsqlparser
+ ${jsqlparser.version}
+
+
+
+ org.mybatis
+ mybatis
+ ${mybatis.version}
+ true
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
- ${spring-boot-dependencies.version}
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 3.2.0
+
+
+ rebel.xml
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ ${java.version}
+ ${java.version}
+ ${project.build.sourceEncoding}
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.1
+
+
+ attach-sources
+
+ jar-no-fork
+
+
+
+
+
+
+
+
-
-
-
- aliyun-repos
- https://maven.aliyun.com/repository/public
-
- false
-
-
-
-
- huaweicloud
- https://mirrors.huaweicloud.com/repository/maven/
-
- false
-
-
-
-
-
\ No newline at end of file
--
Gitee