Full masking of email address including delimiter

In this post under DataMask, I will show with example how to mask a email address including the delimiter.

Below is the complete main class for your reference

Example2

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 Example2 {
public static void main(String[] args) throws DataMaskException {
MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder()
.maskType(MaskType.FULL_MASKING)
.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 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 “EMAIL”.

This will tell “DataMaskManager” instance that the input data format is an email and it has to mask just the username part and not the domain.

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

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

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

Below is the output

Output

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

Please note the “.” delimiter is also masked.

In this way we can mask an email including delimiter.

Leave a comment