| package com.panzhihua.common.utlis; | 
|   | 
| import java.util.regex.Matcher; | 
| import java.util.regex.Pattern; | 
|   | 
| /** | 
|  * @description: 身份证手机号脱敏处理 | 
|  * @author: Null | 
|  * @date: 2021/3/16 15:53 | 
|  */ | 
| public class SensitiveUtil { | 
|   | 
|     /** | 
|      * 手机号码脱敏处理 | 
|      * | 
|      * @param phoneNumber | 
|      * @return | 
|      */ | 
|     public static String desensitizedPhoneNumber(String phoneNumber) { | 
|         if (StringUtils.isNotEmpty(phoneNumber)) { | 
|             phoneNumber = phoneNumber.replaceAll("(\\w{3})\\w*(\\w{4})", "$1****$2"); | 
|         } | 
|         return phoneNumber; | 
|     } | 
|   | 
|     /** | 
|      * 身份证号码脱敏处理 | 
|      * | 
|      * @param idNumber | 
|      * @return | 
|      */ | 
|     public static String desensitizedIdNumber(String idNumber) { | 
|         if (!StringUtils.isEmpty(idNumber)) { | 
|             if (idNumber.length() == 15) { | 
|                 idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{3})", "$1******$2"); | 
|             } | 
|             if (idNumber.length() == 18) { | 
|                 idNumber = idNumber.replaceAll("(\\w{6})\\w*(\\w{4})", "$1********$2"); | 
|             } | 
|         } | 
|         return idNumber; | 
|     } | 
|   | 
|   | 
|     public static String replaceName(String str) { | 
|         if(StringUtils.isNotEmpty(str)){ | 
|             if(str.length()==2){ | 
|                 str=str.replace(str.substring(1),"*"); | 
|             } | 
|             if(str.length()>2) { | 
|                 str=str.replace(str.substring(1,str.length()-1),"*"); | 
|             } | 
|         } | 
|         return str; | 
|     } | 
| } |