Middle masking of email address with configured delimiter

In this post under DataMask, I will show with example how to do middle masking of email address excluding masking of delimiter.

So if the email address is “john.doe@gmail.com”, the output should be “jo**.*oe@gmail.com”. The delimiter “.” is also is excluded.

Below is the complete main class

Main class

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 Example15 {
public static void main(String[] args) throws DataMaskException {
MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder()
.maskType(MaskType.MIDDLE_MASKING)
.leftCharacterCount(2)
.rightCharacterCount(2)
.delimiter(".")
.dataFormatType(DataFormatType.EMAIL).build();
DataMaskManager dataMaskManager = new DataMaskManager();
String result = dataMaskManager.maskText(maskInformationDTO, "john.doe@gmail.com");
System.out.println(result);
}
}

In the above code, at line 11, I created an instance of MaskInformationDTO class and configured it do side masking of a email address excluding delimiter “.”.

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

At line 19, I call “maskText” method of “DataMaskManager” and pass the actual text and instance of “MaskInformationDTO” as arguments.

At line 20, the result is printed to console.

Below is the output

Output

jo**.*oe@gmail.com

Leave a Reply