Tools - masking sensitive information rules

/ ** 
* Class Name: The DisplayUtil <br>
* Class Description: masking rule sensitive information <br>
* /
public class The DisplayUtil {

/ **
* 3 end of the first phone number display 4, the intermediate was replaced with an asterisk hidden, such as : 4213 138 ****
*
* @param Mobile
* @return
* /
public static String displayMobile (String Mobile) {
IF (StringUtils.isBlank (Mobile) || mobile.length () <=. 8) {
return Mobile;
}

wordMask return (Mobile,. 3,. 4, "*");
}

/ **
* area code and phone number last 4 bits in place of the intermediate hidden by an asterisk, such as: 010 4213 ****
*
* @param telephone
* @ return
* /
public static String displayTelephone (String Telephone) {
if(StringUtils.isBlank(telephone)) {
return telephone;
}
String result;
if (telephone.length() > 8) {
if (telephone.contains("-")) {
String[] temp = telephone.split("-");
result = temp[0] + "****" + temp[1].substring(temp[1].length() - 4, temp[1].length());
} else {
result = telephone.substring(0, 3) + "****" + telephone.substring(telephone.length() - 4, telephone.length());
}
} else {
result = "****" + telephone.substring(telephone.length() - 4, telephone.length());
}

return result;
}

/ **
* ID No. 3 show the first end 3, an intermediate hidden by an asterisk in place, such as: 012 421 *******
*
* @param idCard
* @return
* /
public static String displayIDCard (String idCard) {
IF (StringUtils.isBlank (idCard)) {
return idCard;
}

return wordMask (idCard, three, 3, "*");
}

/ **
* 3 end of the first display card 3, the intermediate with an asterisk hidden place, such as: ******** 622 123
*
* @param cardNo
* @return
* /
public static String displayBankCard (String cardNo) {
IF (StringUtils.isBlank (cardNo) || cardNo.length () <10) {
cardNo return;
}

wordMask return (cardNo, 3, 3, "*");
}

/ **
* E-mail like the first two and the last one character, and the mailbox @ domain information, such as: ye **** [email protected]
*
* @param In Email
* @return
* /
public static String displayEmail (String In Email) {
IF (StringUtils.isBlank (In Email)) {
return In Email;
}
String [] = email.split TEMP ( "@");

return wordMask ( TEMP [0],. 1,. 1, "*") + "@" + TEMP [. 1];
}

/ **
* mask words, such as: The Xiaoming: Ming Zhang *
* mask word, such as : Xiaoming as: * Description
* plurality of word masks, such as: Zhang obviously as: Ming Zhang **
*
* @param name
* @return
* /
public static String displayName(String name) {
if(StringUtils.isBlank(name) || name.length() == 1) {
return name;
}
if (name.length() == 2) {
return "*" + name.substring(1, 2);
}

return wordMask(name, 0, 1, "*");
}

/**
* Cvv全隐藏,如: ***
*
* @param cvv
* @return
*/
public static String displayCvv(String cvv) {
if(StringUtils.isBlank(cvv)) {
return cvv;
}
return "***";
}

/**
* Expdate全隐藏,如: ****
*
@Param expdate *
* @return
* /
public static String displayExpdate (String expdate) {
IF (StringUtils.isBlank (expdate)) {
return expdate;
}
return "****";
}

/ **
* string deprotection processing Min -
*
* @param Word is desensitized character
* @param startLength starts to be retained over the length of n bits before
* @param endLength after the reserved length of the n-bit I
* @param pad fill character
* * /
public String wordMask static (String Word, startLength int, int endLength, String PAD) {

IF (startLength + endLength> word.length ()) {
return org.apache.commons.lang3.StringUtils.leftPad("", word.length() - 1, pad);
}

String startStr = word.substring(0, startLength);

String endStr = word.substring(word.length() - endLength, word.length());

return startStr + org.apache.commons.lang3.StringUtils.leftPad("", word.length() - startLength - endLength, pad) + endStr;

}
}

Guess you like

Origin www.cnblogs.com/tieandxiao/p/10931439.html