From a5c773cde8b5e5ffb097838b3bdcd5e4f8e88e08 Mon Sep 17 00:00:00 2001 From: YUJT Date: Fri, 16 Jul 2021 10:29:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=84=B1=E6=95=8F=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epdc/commons/tools/utils/ModuleUtils.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) 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, "*"); + } + }