Class PiiMasker
Utility class for partially masking PII fields (email, phone, address) so users can recognize their data without exposing full details.
public static class PiiMasker
- Inheritance
-
objectPiiMasker
Methods
MaskEmail(string?)
Masks an email address, preserving the first character of the local part and the full domain. Example: "jane@example.com" → "j***@example.com"
public static string? MaskEmail(string? email)
Parameters
emailstringThe email address to mask.
Returns
- string
The masked email, or null if the input is null or whitespace.
MaskPhone(string?)
Masks a phone number, preserving only the last 4 digits. Example: "(303) 555-0100" → "--0100"
public static string? MaskPhone(string? phone)
Parameters
phonestringThe phone number to mask.
Returns
- string
The masked phone, or null if the input is null or whitespace.
MaskStreetAddress(string?, string?)
Masks street address lines by returning a generic masked indicator. Callers should handle city, state, and ZIP code values separately if needed.
public static string? MaskStreetAddress(string? streetAddress1, string? streetAddress2)
Parameters
streetAddress1stringThe primary street address line.
streetAddress2stringThe secondary street address line (apt, suite, etc.).
Returns
- string
A masked street indicator, or null if both street address lines are null or whitespace. Callers should log a warning when this returns null — a missing address likely indicates an upstream data issue that warrants investigation.