Finally we had the most powerful in the history of data processing algorithms desensitization

Haha, heading the party, and to apologize to you!

Closer to home.

Our application system for the protection of user privacy, sensitive information about users often do desensitization desensitization display or storage, such as a user ID number, phone number, bank cards, and so on. In the payment system or financial system, data security is the top priority, desensitization processing of data is mandatory.

[ID number 120115201406180712 after desensitization desensitization example]: 120 115 0712 ********
After the [bank] 9558820200019833888 card desensitization desensitization example: 955 882 3888 *********
[Phone number] 18810754438 after desensitization desensitization example: 38 188 ******

 

The principle is very simple algorithm, is reserved character head and tail, the middle part such as an asterisk "*" as a mask to represent special characters.

Many online similar algorithms. Here are a for reference:

import java.util.Arrays;
import java.util.concurrent.atomic.AtomicInteger;
    public  static String tuoMin (STR String, int headCharCount, int tailCharCount) {
         IF (str.length () <+ headCharCount tailCharCount) {
             the throw  new new an IllegalArgumentException ( "plain text is too short, not desensitization" );
        }
        String repeat = "";

        int len = str.length() - headCharCount - tailCharCount;
        if (len > 0) {
            char[] buf = new char[len];
            AtomicInteger integer = new AtomicInteger(0);
            Arrays.asList(new Integer[len]).stream().forEach(b -> buf[integer.getAndIncrement()] = '*');
            repeat = new String(buf);
        }
        return str.substring(0, headCharCount) + repeat + str.substring(str.length() - tailCharCount);
    }

 

Test Case:

    public static void main(String[] args) {
        System.out.println(tuoMin("120115201406180712", 6, 4));
        System.out.println(tuoMin("9558820200019833888", 6, 4));
        System.out.println(tuoMin("18810754438", 3, 2));
    }

Output results:

120115********0712
955882*********3888
188******38

 

Guess you like

Origin www.cnblogs.com/buguge/p/11930553.html