public class Censor extends Object
| Constructor and Description |
|---|
Censor()
This constructor creates a new
Censor object that uses the default 'X' character
for masking. |
Censor(char maskingCharacter)
This constructor creates a new
Censor object that uses the specified character
for masking. |
| Modifier and Type | Method and Description |
|---|---|
String |
process(String value,
String mask)
This method masks the given string according to the groups specified in the specified mask.
|
public Censor()
Censor object that uses the default 'X' character
for masking.public Censor(char maskingCharacter)
Censor object that uses the specified character
for masking.maskingCharacter - The character to be used for masking the sensitive characters.public String process(String value, String mask)
For example, a credit card number of 1234-5678-9012-3456 would be masked as follows with these masks:
^\d{4}-(\d{4})-(\d{4})-\d{4}$ yields: 1234-XXXX-XXXX-3456
^\d{4}(-(\d{4}-){2})\d{4}$ yields: 1234XXXXXXXXXXX3456
^((\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:
^(\d{4}-){3}\d{4}$ yields: 1234-5678-XXXXX3456
value - The value to be masked.mask - The regular expression used to extract and mask the sensitive information.Copyright © 2014 Crater Dog Technologies(TM). All rights reserved.