|
@@ -2,7 +2,15 @@ package com.zhongzheng.common.type;
|
|
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import cn.hutool.crypto.symmetric.AES;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.zhongzheng.common.core.domain.model.LoginUser;
|
|
|
+import com.zhongzheng.common.utils.SecurityUtils;
|
|
|
+import com.zhongzheng.common.utils.TelPhoneUtils;
|
|
|
import org.apache.ibatis.type.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.security.core.token.Token;
|
|
|
+import org.springframework.security.core.token.TokenService;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
@@ -19,7 +27,8 @@ public class EncryptHandler implements TypeHandler<String> {
|
|
|
|
|
|
public static final boolean ENCRYPT_STATUS = true; //是否开启字段加密
|
|
|
|
|
|
-
|
|
|
+ @Value("${phone.conceal:false}")
|
|
|
+ private static boolean phoneConceal;
|
|
|
|
|
|
public static String decrypt(String value) {
|
|
|
if (null == value) {
|
|
@@ -28,7 +37,16 @@ public class EncryptHandler implements TypeHandler<String> {
|
|
|
if (value.length()<=20 ) {
|
|
|
return value;
|
|
|
}
|
|
|
- return SecureUtil.aes(KEYS).decryptStr(value);
|
|
|
+ String s = SecureUtil.aes(KEYS).decryptStr(value);
|
|
|
+ if (phoneConceal){
|
|
|
+ //开启手机号码加密
|
|
|
+ LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
+ if (s.length() <= 11 &&
|
|
|
+ (ObjectUtils.isNull(loginUser.getPhoneConcealSign()) || loginUser.getPhoneConcealSign() != 1)){
|
|
|
+ return TelPhoneUtils.hideTelPhone(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return s;
|
|
|
}
|
|
|
|
|
|
public static String encrypt(String value){
|
|
@@ -38,6 +56,7 @@ public class EncryptHandler implements TypeHandler<String> {
|
|
|
if(ENCRYPT_STATUS){
|
|
|
AES aes = SecureUtil.aes(KEYS);
|
|
|
String encrypt = aes.encryptHex(value);
|
|
|
+
|
|
|
return encrypt;
|
|
|
}else{
|
|
|
return value;
|