package com.util;import org.apache.commons.lang3.StringUtils;public class DataDesensitizedUtils { public static String desensitizedName(String fullName) { if (StringUtils.isNotBlank(fullName)) { String name = StringUtils.left(fullName, 1); return StringUtils.rightPad(name, StringUtils.length(fullName), "*"); } return fullName; } public static String desensitizedPhoneNumber(String phoneNumber) { if (StringUtils.isNotBlank(phoneNumber)) { phoneNumber = phoneNumber.replaceAll("(\w{3})\w*(\w{3})", "$1*****$2"); } return phoneNumber; } public static String desensitizedIdNumber(String idNumber) { if (StringUtils.isNotBlank(idNumber)) { return StringUtils.left(idNumber, 6).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(idNumber, 3), StringUtils.length(idNumber), "*"), "******")); } return idNumber; } public static String desensitizedAddress(String address) { if (StringUtils.isNotBlank(address)) { return StringUtils.left(address, 3).concat(StringUtils.removeStart(StringUtils.leftPad(StringUtils.right(address, address.length() - 11), StringUtils.length(address), "*"), "***")); } return address; } public static void main(String[] args) { System.out.println(desensitizedName("张三")); System.out.println(desensitizedPhoneNumber("15085375241")); System.out.println(desensitizedIdNumber("122424205003164013")); System.out.println(desensitizedAddress("浙江省杭州市滨江区")); }}
Java对姓名,手机号,身份证号,地址进行脱敏
时间:2023-06-13
相关推荐