Side masking of email address without configuring delimiter

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

So if the text is “john.doe@gmail.com“, the output should be “**hn****@gmail.com”

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 Example9 {
public static void main(String[] args) throws DataMaskException {
MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder()
.maskType(MaskType.SIDE_MASKING)
.leftCharacterCount(2)
.rightCharacterCount(4)
.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 an email address.

I configured it to side mask 2 characters from the left and 4 characters from the right using “leftCharacterCount” and “rightCharacterCount” methods.

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

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

At line 18, the result is printed to console.

In this way we can do side masking of email address including masking of delimiter.

Below is the output

Output

**hn****@gmail.com

Leave a comment