1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| 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 mobileEncrypt(String mobile) { if (StringUtils.isEmpty(mobile) || (mobile.length() != 11)) { return mobile; } return mobile.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
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("浙江省杭州市滨江区")); } }
|