Package com.irurueta.commons
Class MaskedPanFormatter
- java.lang.Object
-
- com.irurueta.commons.MaskedPanFormatter
-
public class MaskedPanFormatter extends java.lang.Object
Generates a masked PAN where only the last 4 digits are displayed and the remaining ones are masked using digit groupings according to the corresponding credit card network. Notice that this class displays a maximum of 4 digits to remain PCI DSS no matter how many visible digits are requested. If less than request digits are available in provided PAN, then only available digits are displayed as the last digits of masked PAN.
-
-
Field Summary
Fields Modifier and Type Field Description static char
DEFAULT_MASK_CHAR
Default character to use as a masked digit on a credit card PAN.static char
DEFAULT_SEPARATOR_CHAR
Default character to use as a group separator.static int
NUM_VISIBLE_DIGITS
Default number of visible digits to be PCI DSS compliant.
-
Constructor Summary
Constructors Modifier Constructor Description private
MaskedPanFormatter()
Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
format(byte[] digits, CreditCardNetwork network, char maskChar, char separatorChar, int numVisibleDigits)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.static java.lang.String
format(java.lang.String pan)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network.static java.lang.String
format(java.lang.String pan, char maskChar)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network.static java.lang.String
format(java.lang.String pan, char maskChar, char separatorChar)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network.static java.lang.String
format(java.lang.String panOrLastDigits, CreditCardNetwork network)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.static java.lang.String
format(java.lang.String panOrLastDigits, CreditCardNetwork network, char maskChar)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.static java.lang.String
format(java.lang.String panOrLastDigits, CreditCardNetwork network, char maskChar, char separatorChar)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.private static byte[]
toDigits(java.lang.String pan)
Converts a PAN into an array of digits.
-
-
-
Field Detail
-
DEFAULT_MASK_CHAR
public static final char DEFAULT_MASK_CHAR
Default character to use as a masked digit on a credit card PAN.- See Also:
- Constant Field Values
-
DEFAULT_SEPARATOR_CHAR
public static final char DEFAULT_SEPARATOR_CHAR
Default character to use as a group separator.- See Also:
- Constant Field Values
-
NUM_VISIBLE_DIGITS
public static final int NUM_VISIBLE_DIGITS
Default number of visible digits to be PCI DSS compliant.- See Also:
- Constant Field Values
-
-
Method Detail
-
format
public static java.lang.String format(java.lang.String panOrLastDigits, CreditCardNetwork network, char maskChar, char separatorChar)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.- Parameters:
panOrLastDigits
- credit card number (or its last digits) to be masked.network
- credit card network.maskChar
- mask character to be used.separatorChar
- group separator character to be used.- Returns:
- masked PAN.
-
format
public static java.lang.String format(java.lang.String panOrLastDigits, CreditCardNetwork network, char maskChar)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network. This method uses the space as a group separator.- Parameters:
panOrLastDigits
- credit card number (or its last digits) to be masked.network
- credit card network.maskChar
- mask character to be used.- Returns:
- masked PAN.
-
format
public static java.lang.String format(java.lang.String panOrLastDigits, CreditCardNetwork network)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network. This method uses the space as a group separator and the star character as a masked digit.- Parameters:
panOrLastDigits
- credit card number (or its last digits) to be masked.network
- credit card network.- Returns:
- masked PAN.
-
format
public static java.lang.String format(java.lang.String pan, char maskChar, char separatorChar)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network. This method needs a full credit card PAN to detect the credit card network using the former digits, and making visible the latter ones. If a credit card network cannot be determined, default grouping is used instead.- Parameters:
pan
- a full credit card number.maskChar
- mask character to be used.separatorChar
- group separator character to be used.- Returns:
- masked PAN.
-
format
public static java.lang.String format(java.lang.String pan, char maskChar)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network. This method needs a full credit card PAN to detect the credit card network using the former digits, and making visible the latter ones. If a credit card network cannot be determined, default grouping is used instead. This method uses the space as a group separator.- Parameters:
pan
- a full credit card number.maskChar
- mask character to be used.- Returns:
- masked PAN.
-
format
public static java.lang.String format(java.lang.String pan)
Formats a full credit card PAN by making visible only the last digits and masking the remaining ones following the digits grouping required for the detected credit card network. This method needs a full credit card PAN to detect the credit card network using the former digits, and making visible the latter ones. If a credit card network cannot be determined, default grouping is used instead. This method uses the space as a group separator and the star character as a masked digit.- Parameters:
pan
- a full credit card number.- Returns:
- masked PAN.
-
format
private static java.lang.String format(byte[] digits, CreditCardNetwork network, char maskChar, char separatorChar, int numVisibleDigits)
Formats a credit card PAN (or its last digits) by making visible only the last digits and masking the remaining ones following the digits grouping required for provided credit card network.- Parameters:
digits
- array containing the full credit card number (or its last digits) to be masked.network
- credit card network.maskChar
- mask character to be used.separatorChar
- group separator character to be used.numVisibleDigits
- number of visible digits. The number of visible digits must not exceed 4 to remain PCI DSS compliant. Only the last group of digits will be shown unmasked if this value exceed the length of such group.- Returns:
- masked PAN.
-
toDigits
private static byte[] toDigits(java.lang.String pan)
Converts a PAN into an array of digits. Any non digit character is ignored.- Parameters:
pan
- PAN to be converted to digits.- Returns:
- array containing digits within provided PAN.
-
-