From 8b0a46fd0412a3da2028c85449a8749d17248014 Mon Sep 17 00:00:00 2001 From: chenjiahe <763432473@qq.com> Date: 星期五, 07 一月 2022 12:15:57 +0800 Subject: [PATCH] 添加Mysql数据库的AES加解密方法(新增十六进制的判断方法) --- src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java b/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java index 7ab145b..c5579f3 100644 --- a/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java +++ b/src/main/java/com/hx/util/mysql/aes/MysqlHexAes.java @@ -6,6 +6,7 @@ import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import java.io.UnsupportedEncodingException; +import java.util.regex.Pattern; /** * mybatis鏁版嵁搴撶殑AES_ENCRYPT锛堝姞瀵嗭級鍜孉ES_DECRYPT锛堣В瀵嗭級 @@ -45,7 +46,7 @@ decryptCipher.init(Cipher.DECRYPT_MODE, generateMySQLAESKey(aesKey, encoding)); data = new String(decryptCipher.doFinal(Hex.decodeHex(data.toCharArray()))); }catch (Exception e){ - throw new RuntimeException("瑙e瘑澶辫触锛�"+e.getMessage()); + throw new RuntimeException(e); } return data; } @@ -71,9 +72,21 @@ } data = builder.toString().toUpperCase(); } catch (Exception e) { - throw new RuntimeException("鍔犲瘑澶辫触锛�"+e.getMessage()); + throw new RuntimeException(e); } return data; } + /** + * 鍒ゆ柇鏄笉鏄崄鍏繘鍒剁殑瀛楃涓诧紙瀛楁瘝鏄ぇ鍐欑殑锛� + * @param str 闇�瑕佸垽鏂殑瀛楃涓� + * @return true or false + */ + public static boolean isHexStrValid(String str) { + String pattern = "^[0-9A-F]+$"; + return Pattern.compile(pattern).matcher(str).matches(); + } + + + } -- Gitblit v1.8.0