欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

Java对姓名,手机号,身份证号,地址进行脱敏

时间:2023-06-13

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("浙江省杭州市滨江区")); }}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。