From c3811d01d1929a98a0f34f70ca187d82ee312dbb Mon Sep 17 00:00:00 2001 From: manailin <261030956@qq.com> Date: 星期三, 03 十一月 2021 17:26:50 +0800 Subject: [PATCH] Merge branch 'test' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ into test --- springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/helper/encrypt/DoEncrytDecrypt.java | 41 +++++++++++++++++++++++++++-------------- 1 files changed, 27 insertions(+), 14 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/helper/encrypt/DoEncrytDecrypt.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/helper/encrypt/DoEncrytDecrypt.java index 5c7e621..4fd36d7 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/helper/encrypt/DoEncrytDecrypt.java +++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/helper/encrypt/DoEncrytDecrypt.java @@ -1,23 +1,24 @@ package com.panzhihua.common.model.helper.encrypt; -import com.panzhihua.common.model.helper.AESUtil; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; - import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import com.panzhihua.common.model.helper.AESUtil; + +import lombok.extern.slf4j.Slf4j; + /*** - * 默认实现: AES 128 加密、解密 - * 可自定义实现{@link IEncryptDecrypt }接口 + * 默认实现: AES 128 加密、解密 可自定义实现{@link IEncryptDecrypt }接口 * * @author cedoo * @since 2021-4-1 10:40:52 */ @Slf4j @Component -public class DoEncrytDecrypt implements IEncryptDecrypt{ +public class DoEncrytDecrypt implements IEncryptDecrypt { @Value("${domain.aesKey:}") private String aesKey; @@ -28,12 +29,17 @@ if (field.getType() == String.class) { field.setAccessible(true); for (Annotation annotation : field.getAnnotations()) { - if (annotation.annotationType() == EncryptDecryptField.class || annotation.annotationType() == EncryptQuery.class) { + if (annotation.annotationType() == EncryptDecryptField.class + || annotation.annotationType() == EncryptQuery.class) { log.debug("加密字段:" + field.getName()); Object fieldVal = field.get(parameterObject); - if(fieldVal!=null) { - String encryptedStr = AESUtil.encrypt128(fieldVal.toString(), aesKey); - field.set(parameterObject, encryptedStr); + if (fieldVal != null) { + try { + String encryptedStr = AESUtil.encrypt128(fieldVal.toString(), aesKey); + field.set(parameterObject, encryptedStr); + } catch (Exception e) { + log.debug("加密失败"); + } } } } @@ -53,8 +59,15 @@ if (annotation.annotationType() == EncryptDecryptField.class) { log.debug("解密密字段:" + field.getName()); String fieldVal = field.get(result).toString(); - String decryptVal = AESUtil.decrypt128(fieldVal, aesKey); - field.set(result, decryptVal!=null?decryptVal:fieldVal); + try { + String decryptVal = AESUtil.decrypt128(fieldVal, aesKey); + field.set(result, decryptVal != null ? decryptVal : fieldVal); + } catch (Exception e) { + /** + * 兼容原始未加密数据 + */ + field.set(result, fieldVal); + } } } } -- Gitblit v1.7.1