diff --git a/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ModuleUtils.java b/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ModuleUtils.java index b535665..c9f570e 100644 --- a/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ModuleUtils.java +++ b/epdc-commons-tools/src/main/java/com/elink/esua/epdc/commons/tools/utils/ModuleUtils.java @@ -134,4 +134,47 @@ public class ModuleUtils { } return convertSuccess; } + + /** + * 手机号脱敏(中间四位用*替换) + * + * @param mobile 手机号 + * @return java.lang.String + * @author work@yujt.net.cn + * @date 2021/7/16/0016 10:23 + */ + public static String hideMobile(String mobile) { + if (StringUtils.isNotBlank(mobile)) { + return StringUtils.EMPTY; + } + return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2"); + } + + /** + * 身份证号码脱敏(保留前四位与后六位,中间部分用*号替换) + * + * @param identityNo 身份证号码 + * @return java.lang.String + * @author work@yujt.net.cn + * @date 2021/7/16/0016 10:23 + */ + public static String hideIdentityNo(String identityNo) { + return hideIdentityNo(identityNo, 4, 6); + } + + /** + * 身份证号码脱敏(指定保留头部及尾部的长度,中间部分用*号替换) + * + * @param identityNo 身份证号码 + * @param head 头部保留位数 + * @param tail 尾部保留位数 + * @return java.lang.String + * @author work@yujt.net.cn + * @date 2021/7/16/0016 10:24 + */ + public static String hideIdentityNo(String identityNo, int head, int tail) { + String regex = String.format("(?<=\\w{%d})\\w(?=\\w{%d})", head, tail); + return identityNo.replaceAll(regex, "*"); + } + }