|
@@ -2,14 +2,25 @@ 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.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.CallableStatement;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.util.Properties;
|
|
|
|
|
|
|
|
|
@MappedJdbcTypes(JdbcType.VARCHAR)
|
|
@@ -20,7 +31,6 @@ public class EncryptHandler implements TypeHandler<String> {
|
|
|
public static final boolean ENCRYPT_STATUS = true; //是否开启字段加密
|
|
|
|
|
|
|
|
|
-
|
|
|
public static String decrypt(String value) {
|
|
|
if (null == value) {
|
|
|
return null;
|
|
@@ -28,7 +38,25 @@ 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);
|
|
|
+ Boolean phoneConceal = false;
|
|
|
+ try (InputStream inputStream = EncryptHandler.class.getClassLoader().getResourceAsStream("application.yml")) {
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.load(inputStream);
|
|
|
+ String property = properties.getProperty("conceal");
|
|
|
+ phoneConceal = Boolean.valueOf(property);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ 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 +66,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;
|