public class DesensitizedUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
DesensitizedUtil.DesensitizedType
支持的脱敏类型枚举
|
Constructor and Description |
---|
DesensitizedUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
address(String address,
int sensitiveSize)
【地址】只显示到地区,不显示详细地址,比如:北京市海淀区****
|
static String |
bankCard(String bankCardNo)
【银行卡号脱敏】由于银行卡号长度不定,所以只展示前4位,后面的位数根据卡号决定展示1-4位
例如:
1. "1234 2222 3333 4444 6789 9" -> "1234 **** **** **** **** 9"
2. "1234 2222 3333 4444 6789 91" -> "1234 **** **** **** **** 91"
3. "1234 2222 3333 4444 678" -> "1234 **** **** **** 678"
4. "1234 2222 3333 4444 6789" -> "1234 **** **** **** 6789"
|
static String |
carLicense(String carLicense)
【中国车牌】车牌中间用*代替
eg1:null -》 ""
eg1:"" -》 ""
eg3:苏D40000 -》 苏D4***0
eg4:陕A12345D -》 陕A1****D
eg5:京A123 -》 京A123 如果是错误的车牌,不处理
|
static String |
chineseName(String fullName)
【中文姓名】只显示第一个汉字,其他隐藏为2个星号,比如:李**
|
static String |
clear()
清空为空字符串
|
static String |
clearToNull()
清空为
null |
static String |
desensitized(CharSequence str,
DesensitizedUtil.DesensitizedType desensitizedType)
脱敏,使用默认的脱敏策略
DesensitizedUtil.desensitized("100", DesensitizedUtil.DesensitizedType.USER_ID)) = "0"
DesensitizedUtil.desensitized("段正淳", DesensitizedUtil.DesensitizedType.CHINESE_NAME)) = "段**"
DesensitizedUtil.desensitized("51343620000320711X", DesensitizedUtil.DesensitizedType.ID_CARD)) = "5***************1X"
DesensitizedUtil.desensitized("09157518479", DesensitizedUtil.DesensitizedType.FIXED_PHONE)) = "0915*****79"
DesensitizedUtil.desensitized("18049531999", DesensitizedUtil.DesensitizedType.MOBILE_PHONE)) = "180****1999"
DesensitizedUtil.desensitized("北京市海淀区马连洼街道289号", DesensitizedUtil.DesensitizedType.ADDRESS)) = "北京市海淀区马********"
DesensitizedUtil.desensitized("duandazhi-jack@gmail.com.cn", DesensitizedUtil.DesensitizedType.EMAIL)) = "d*************@gmail.com.cn"
DesensitizedUtil.desensitized("1234567890", DesensitizedUtil.DesensitizedType.PASSWORD)) = "**********"
DesensitizedUtil.desensitized("苏D40000", DesensitizedUtil.DesensitizedType.CAR_LICENSE)) = "苏D4***0"
DesensitizedUtil.desensitized("11011111222233333256", DesensitizedUtil.DesensitizedType.BANK_CARD)) = "1101 **** **** **** 3256"
DesensitizedUtil.desensitized("192.168.1.1", DesensitizedUtil.DesensitizedType.IPV4)) = "192.*.*.*"
|
static String |
email(String email)
【电子邮箱】邮箱前缀仅显示第一个字母,前缀其他隐藏,用星号代替,@及后面的地址显示,比如:d**@126.com
|
static String |
firstMask(String str)
定义了一个first_mask的规则,只显示第一个字符。
|
static String |
fixedPhone(String num)
【固定电话 前四位,后两位
|
static String |
idCardNum(String idCardNum,
int front,
int end)
【身份证号】前1位 和后2位
|
static String |
ipv4(String ipv4)
IPv4脱敏,如:脱敏前:192.0.2.1;脱敏后:192.*.*.*。
|
static String |
ipv6(String ipv6)
IPv6脱敏,如:脱敏前:2001:0db8:86a3:08d3:1319:8a2e:0370:7344;脱敏后:2001:*:*:*:*:*:*:*
|
static String |
mobilePhone(String num)
【手机号码】前三位,后4位,其他隐藏,比如135****2210
|
static String |
password(String password)
【密码】密码的全部字符都用*代替,比如:******
|
static Long |
userId()
【用户id】不对外提供userId
|
public static String desensitized(CharSequence str, DesensitizedUtil.DesensitizedType desensitizedType)
DesensitizedUtil.desensitized("100", DesensitizedUtil.DesensitizedType.USER_ID)) = "0" DesensitizedUtil.desensitized("段正淳", DesensitizedUtil.DesensitizedType.CHINESE_NAME)) = "段**" DesensitizedUtil.desensitized("51343620000320711X", DesensitizedUtil.DesensitizedType.ID_CARD)) = "5***************1X" DesensitizedUtil.desensitized("09157518479", DesensitizedUtil.DesensitizedType.FIXED_PHONE)) = "0915*****79" DesensitizedUtil.desensitized("18049531999", DesensitizedUtil.DesensitizedType.MOBILE_PHONE)) = "180****1999" DesensitizedUtil.desensitized("北京市海淀区马连洼街道289号", DesensitizedUtil.DesensitizedType.ADDRESS)) = "北京市海淀区马********" DesensitizedUtil.desensitized("duandazhi-jack@gmail.com.cn", DesensitizedUtil.DesensitizedType.EMAIL)) = "d*************@gmail.com.cn" DesensitizedUtil.desensitized("1234567890", DesensitizedUtil.DesensitizedType.PASSWORD)) = "**********" DesensitizedUtil.desensitized("苏D40000", DesensitizedUtil.DesensitizedType.CAR_LICENSE)) = "苏D4***0" DesensitizedUtil.desensitized("11011111222233333256", DesensitizedUtil.DesensitizedType.BANK_CARD)) = "1101 **** **** **** 3256" DesensitizedUtil.desensitized("192.168.1.1", DesensitizedUtil.DesensitizedType.IPV4)) = "192.*.*.*"
str
- 字符串desensitizedType
- 脱敏类型;可以脱敏:用户id、中文名、身份证号、座机号、手机号、地址、电子邮件、密码public static String clear()
public static String clearToNull()
null
public static Long userId()
public static String firstMask(String str)
str
- 字符串public static String chineseName(String fullName)
fullName
- 姓名public static String idCardNum(String idCardNum, int front, int end)
idCardNum
- 身份证front
- 保留:前面的front位数;从1开始end
- 保留:后面的end位数;从1开始public static String fixedPhone(String num)
num
- 固定电话public static String mobilePhone(String num)
num
- 移动电话;public static String address(String address, int sensitiveSize)
address
- 家庭住址sensitiveSize
- 敏感信息长度public static String email(String email)
email
- 邮箱public static String password(String password)
password
- 密码public static String carLicense(String carLicense)
carLicense
- 完整的车牌号public static String bankCard(String bankCardNo)
1. "1234 2222 3333 4444 6789 9" -> "1234 **** **** **** **** 9"
2. "1234 2222 3333 4444 6789 91" -> "1234 **** **** **** **** 91"
3. "1234 2222 3333 4444 678" -> "1234 **** **** **** 678"
4. "1234 2222 3333 4444 6789" -> "1234 **** **** **** 6789"
bankCardNo
- 银行卡号public static String ipv4(String ipv4)
ipv4
- IPv4地址Copyright © 2024. All rights reserved.