Enum Class DesensitizeType

java.lang.Object
java.lang.Enum<DesensitizeType>
tech.riemann.nif.web.desensitize.DesensitizeType
All Implemented Interfaces:
Serializable, Comparable<DesensitizeType>, Constable

public enum DesensitizeType extends Enum<DesensitizeType>
脱敏类型枚举

定义各种数据脱敏规则

使用示例:

@Desensitize(type = DesensitizeType.MOBILE)
private String mobile; // 138****1234

@Desensitize(type = DesensitizeType.ID_CARD)
private String idCard; // 110**********123
Author:
Kerbores(kerbores@riemann.tech)
  • Enum Constant Details

    • MOBILE

      public static final DesensitizeType MOBILE
      手机号脱敏

      规则:保留前3位和后4位,中间用****替换

      示例:138****1234

    • ID_CARD

      public static final DesensitizeType ID_CARD
      身份证号脱敏

      规则:保留前3位和后4位,中间按实际长度用*替换(长度保持,不泄露位数结构)

      示例:110***********1234

    • EMAIL

      public static final DesensitizeType EMAIL
      邮箱脱敏

      规则:保留首字母和@后面的域名,中间用***替换

      示例:k***@example.com;a@x.com → a***@x.com(单字符用户名也脱敏,原实现原样返回泄露)

    • BANK_CARD

      public static final DesensitizeType BANK_CARD
      银行卡号脱敏

      规则:保留前4位和后4位,中间按实际长度用*替换(长度保持,不泄露位数结构)

      示例:6222********1234

    • ADDRESS

      public static final DesensitizeType ADDRESS
      地址脱敏

      规则:保留前6个字符或一半长度(取较小值),后面用****替换

      示例:北京市朝阳区****

    • NAME

      public static final DesensitizeType NAME
      姓名脱敏

      规则:保留首字符,后面用*替换

      示例:张*、李**

    • PASSWORD

      public static final DesensitizeType PASSWORD
      密码脱敏

      规则:全部替换为******

      示例:******

    • CUSTOM

      public static final DesensitizeType CUSTOM
      自定义脱敏

      规则:通过@Desensitize注解的prefixKeep、suffixKeep、replacer参数自定义

  • Method Details

    • values

      public static DesensitizeType[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DesensitizeType valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • desensitize

      public String desensitize(String value)
      脱敏方法
      Parameters:
      value - 原始值
      Returns:
      脱敏后的值