Full masking of email address with configured delimiter

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

So if the text is “john.doe@gmail.com”, the output should be “****.***@gmail.com”. The delimiter “.” is not masked, it 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 Example11 {
public static void main(String[] args) throws DataMaskException {
MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder()
.maskType(MaskType.FULL_MASKING)
.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 full masking of an email address excluding delimiter “.” by calling “delimiter” function and passing dot as argument.

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 full masking of email address excluding the delimiter.

Below is the output

Output

****.***@gmail.com

Leave a comment