From 893a032ceefb15cc7ed01592a36c18a5592edfd1 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 14 一月 2022 14:30:56 +0800 Subject: [PATCH] Mysql数据库AES加密工具 --- src/main/java/com/hx/mybatis/aes/handler/GenericStringHandler.java | 14 +++++++------- src/main/java/com/hx/util/mysql/aes/MysqlHexAesTool.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/hx/mybatis/aes/handler/GenericStringHandler.java b/src/main/java/com/hx/mybatis/aes/handler/GenericStringHandler.java index b31fbf1..2598bdf 100644 --- a/src/main/java/com/hx/mybatis/aes/handler/GenericStringHandler.java +++ b/src/main/java/com/hx/mybatis/aes/handler/GenericStringHandler.java @@ -1,7 +1,7 @@ package com.hx.mybatis.aes.handler; import com.hx.mybatis.aes.springbean.VariableAesKey; -import com.hx.util.mysql.aes.MysqlHexAes; +import com.hx.util.mysql.aes.MysqlHexAesTool; import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.MappedJdbcTypes; @@ -32,9 +32,9 @@ @Override public String getNullableResult(ResultSet rs, String columnName) throws SQLException { String data = rs.getString(columnName); - if(data != null && data.length()%32==0 && MysqlHexAes.isHexStrValid(data)){ + if(data != null && data.length()%32==0 && MysqlHexAesTool.isHexStrValid(data)){ try{ - data = MysqlHexAes.decryptData(data, VariableAesKey.getAesKey(columnName),null); + data = MysqlHexAesTool.decryptData(data, VariableAesKey.getAesKey(columnName),null); }catch (Exception e){ //e.printStackTrace(); } @@ -45,9 +45,9 @@ @Override public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException { String data = rs.getString(columnIndex); - if(data != null && data.length()%32==0 && MysqlHexAes.isHexStrValid(data)){ + if(data != null && data.length()%32==0 && MysqlHexAesTool.isHexStrValid(data)){ try{ - data = MysqlHexAes.decryptData(data, VariableAesKey.getAesKey(null),null); + data = MysqlHexAesTool.decryptData(data, VariableAesKey.getAesKey(null),null); }catch (Exception e){ //e.printStackTrace(); } @@ -58,9 +58,9 @@ @Override public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { String data = cs.getString(columnIndex); - if(data != null && data.length() < 129 && data.length()%32==0 && MysqlHexAes.isHexStrValid(data)){ + if(data != null && data.length() < 129 && data.length()%32==0 && MysqlHexAesTool.isHexStrValid(data)){ try{ - data = MysqlHexAes.decryptData(data, VariableAesKey.getAesKey(null),null); + data = MysqlHexAesTool.decryptData(data, VariableAesKey.getAesKey(null),null); }catch (Exception e){ //e.printStackTrace(); } diff --git a/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java b/src/main/java/com/hx/util/mysql/aes/MysqlHexAesTool.java similarity index 98% rename from src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java rename to src/main/java/com/hx/util/mysql/aes/MysqlHexAesTool.java index c2a5d0a..8ac6a9c 100644 --- a/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java +++ b/src/main/java/com/hx/util/mysql/aes/MysqlHexAesTool.java @@ -14,7 +14,7 @@ * @author CJH * @Date 2021-01-06 */ -public class MysqlHexAes { +public class MysqlHexAesTool { public static SecretKeySpec generateMySQLAESKey(final String key, final String encoding) { -- Gitblit v1.8.0