Package craterdog.smart
Class Censor
java.lang.Object
craterdog.smart.Censor
This class performs the masking function on a specified string value using a specified mask.
- Author:
- Yan Ma, Derk Norton
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Censor
public Censor()This constructor creates a newCensorobject that uses the default 'X' character for masking. -
Censor
public Censor(char maskingCharacter) This constructor creates a newCensorobject that uses the specified character for masking.- Parameters:
maskingCharacter- The character to be used for masking the sensitive characters.
-
-
Method Details
-
process
This method masks the given string according to the groups specified in the specified mask. Parentheses are used to group the characters to be masked. You should make sure that no parenthesis are used in the parts that should remain as plain text.For example, a credit card number of 1234-5678-9012-3456 would be masked as follows with these masks:
-
mask pattern:
^\d{4}-(\d{4})-(\d{4})-\d{4}$yields:1234-XXXX-XXXX-3456 -
mask pattern:
^\d{4}(-(\d{4}-){2})\d{4}$yields:1234XXXXXXXXXXX3456 -
mask pattern:
^((\d{4}-){3})\d{4}$yields:XXXXXXXXXXXXXXX3456
The java.util.regex.Pattern and java.util.regex.Matcher classes are used to locate the groups included in the round brackets. Please note, if the group is included in a repetition such as *, + or {m,n}, only the last appearance of the group would be masked.
For example:
-
mask pattern:
^(\d{4}-){3}\d{4}$yields:1234-5678-XXXXX3456
- Parameters:
value- The value to be masked.mask- The regular expression used to extract and mask the sensitive information.- Returns:
- The masked value.
-
mask pattern:
-