All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zhibaocloud.carbon.intg.desensitization.CarbonEmailDesensitization Maven / Gradle / Ivy

Go to download

智保云投保通道开发 SDK。定义数据模型以及数据交互所支持的加解密方法

The newest version!
package com.zhibaocloud.carbon.intg.desensitization;


import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author yangtuo
 */
public class CarbonEmailDesensitization implements CarbonStringDesensitization {

  /**
   * 邮箱正则(半匹配)
   */
  private static final Pattern DEFAULT_PATTERN = Pattern.compile(
      "([A-Za-z0-9_\\-.])+@([A-Za-z0-9_\\-.])+\\.([A-Za-z]{2,4})");

  /**
   * 邮箱脱敏
   */
  @Override
  public String desensitize(String original) {
    Matcher matcher = DEFAULT_PATTERN.matcher(original);
    while (matcher.find()) {
      String group = matcher.group();
      int l = group.lastIndexOf("@");
      original = original.replace(group, Symbol.getSymbol(l, Symbol.STAR) + group.substring(l));
    }
    return original;
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy