A tiny Java utility for masking sensitive text while keeping the last 4 characters visible.
SensitiveDataMasker helps prevent sensitive values from being fully exposed in logs or console output by masking all characters except the last four.
4532123412345678 → ************5678
- Java 21
- Maven
- JUnit 5
String masked = SensitiveDataMasker.mask("4532123412345678");
System.out.println(masked);Output:
************5678
The project uses JUnit 5 to verify the masking behavior, including boundary cases such as:
- Strings with fewer than 4 characters
- Strings with exactly 4 characters
- Strings longer than 4 characters
- Typical sensitive values
Run the tests with:
mvn test- Credit card masking
- API key masking
- Sensitive log data
- Developer tools
A small JavaLabs.io utility for experimenting with reusable Java components, automated testing, and practical data-protection patterns.
Part of JavaLabs.io, a collection of Java-first experiments focused on building reusable components and backend systems.
