Full masking of delimited text with configured delimiter

In this post under DataMask, I will show with example how to do full masking a simple delimited text excluding masking of delimiter.

So if the text is “1111-2222-3333-4444”, the output should be “

As you can see from the output the numbers are masked but delimiter “-” is not masked.

Below is the complete main class for your reference

Example5

package core;
import io.github.freewarelabs.datamask.core.DataFormatType;
import io.github.freewarelabs.datamask.core.DataMaskManager;
import io.github.freewarelabs.datamask.core.MaskInformationDTO;
import io.github.freewarelabs.datamask.core.MaskType;
import io.github.freewarelabs.datamask.core.exception.DataMaskException;
public class Example5 {
public static void main(String[] args) throws DataMaskException {
MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder()
.maskType(MaskType.FULL_MASKING)
.delimiter("-")
.dataFormatType(DataFormatType.TEXT).build();
DataMaskManager dataMaskManager = new DataMaskManager();
String result = dataMaskManager.maskText(maskInformationDTO, "1111-2222-3333-4444");
System.out.println(result);
}
}

In the above code, at line 11, I create and configure an instance of “MaskInformationDTO” class.

While configuring “MaskInformationDTO” instance I am setting the mask type to “FULL_MASKING” and data format type as “TEXT”.

I also configure the delimiter that should be excluded from masking by calling “delimiter” method and passing the delimiter “-” as argument. Refer to line 13

This will tell “DataMaskManager” instance that the input data format is a simple text and it has to mask full text excluding the delimiter “-“.

At line 16, I create an instance of “DataMaskManager” class.

At line 17, I call non-static “maskText” method of “DataMaskManager” class and pass instance of “MaskInformationDTO” created at line 11 and actual text to be masked as an argument.

This method returns a masked text which is printed to the console.

Below is the output

Output

****-****-****-****

In this way we can do full masking a simple delimited text excluding masking of delimiter.

Leave a comment