Masking Utility
The ADS.Masking.Utils library provides a set of utility extension methods for masking sensitive information such as phone numbers, Social Security numbers (SSNs), credit card numbers, and email addresses. These methods are designed to enhance data security and protect personal information by replacing certain characters with a masking character.
Service: MaskingExtensionsUtils
The MaskingExtensionsUtils class is a static class that provides the following masking methods:
1. MaskPhoneNumber
Description: Masks a phone number while optionally preserving the country code.
Parameters:
- phoneNumber (string): Phone number without the country code (mandatory).
- countryCode (string, optional): Country code.
- maskWith (char, optional, default: 'X'): Character to mask with.
Returns: A masked phone number, preserving the last three digits and optionally adding the country code.
Example Usage: string maskedPhone = "1234567890".MaskPhoneNumber("+1");
Output: +1 XXXXXXX890
2. MaskSSN
Description: Masks a Social Security Number (SSN), preserving only the last four digits.
Parameters:
- ssnNumber (string): The full SSN (mandatory).
- maskWith (char, optional, default: 'X'): Character to mask with.
Returns: A masked SSN in the format XXX-XX-####.
Example Usage: string maskedSSN = "123-45-6789".MaskSSN();
Output: XXX-XX-6789
3. MaskCardNumber
Description: Masks a credit/debit card number, preserving only the last four digits.
Parameters:
- cardNumber (string): The full card number (mandatory).
- maskWith (char, optional, default: 'X'): Character to mask with.
Returns: A masked card number with all but the last four digits replaced.
Example Usage: string maskedCard = "1234567812345678".MaskCardNumber();
Output: XXXXXXXXXXXX5678
4. MaskEmail
Description: Masks an email address, keeping part of the local name visible and preserving the domain.
Parameters:
- emailAddress (string): The email address to be masked (mandatory).
- maskWith (char, optional, default: '*'): Character to mask with.
Returns: A masked email address with part of the local part replaced.
Example Usage: string maskedEmail = "user@example.com".MaskEmail();
Output: us***@example.com
Exceptions: Throws ArgumentException if the email format is invalid.
5. MaskInput
Description: Masks a given input string based on a specified pattern or format.
Parameters:
- input (string): The input text to be masked (mandatory).
- pattern (string): The masking pattern (optional).
- format (string, optional): The required format.
Returns: A masked string according to the given pattern or format.
Example Usage: string maskedInput = "AB123456".MaskInput("\d", "XX-XXXXXX");
Output: XX-123456
Exceptions: Throws an exception if the input format and provided format do not match.