In this post under DataMask, I will show with example how to do side masking of delimited text including masking of delimiter.
So if the text is “1111-2222-3333-4444”, the output should be “***1-2222-333******”. The delimiter “.” is also masked, it is not 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 Example12 { public static void main(String[] args) throws DataMaskException { MaskInformationDTO maskInformationDTO = MaskInformationDTO.builder() .maskType(MaskType.SIDE_MASKING) .leftCharacterCount(3) .rightCharacterCount(6) .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 created an instance of MaskInformationDTO class and configured it do side masking of a text including delimiter “-“.
At line 17, I create an instance of “DataMaskManager”.
At line 18, I call “maskText” method of “DataMaskManager” and pass the actual text and instance of “MaskInformationDTO” as arguments.
At line 19, the result is printed to console.
Below is the output
Output
***1-2222-333******