<a href="https://www.buymeacoffee.com/eduardoeljaiek" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 35px !important;width: 125px !important;" ></a> **Last Update**: 19.04.2026 *** ***JMaskify*** is an open-source Java library designed to safeguard sensitive data with versatile and customizable masking techniques. Whether your application handles personal, financial, or confidential information, _JMaskify_ ensures its security through intuitive APIs and advanced masking strategies. ## Key Features - **Versatile Masking**: Supports fixed-length anonymization, Base64 encoding, Debit/Credit Card Numbers, JSON, and multiline text masking. - **Flexible API**: Easily adaptable for use cases involving [[#2. JSON Masking | JSON structures]] and [[#3. Multiline Text Masking | multiline text]]. - **Open Source**: MIT-licensed to encourage collaboration and transparency. ## Project Requirements To work with *JMaskify*, ensure the following tools and dependencies are installed: - **JDK**: Version 17 or higher - **Build Tool**: Maven or Gradle ## Dependencies *JMaskify* leverages the following key libraries: - **Jackson**: JSON processing (`jackson-databind`) - **Apache Commons Codec**: Encoding utilities - **SLF4J**: Logging framework ## Getting Started ### Installation JMaskify is available on Maven Central. Add the dependency to your project: ```xml <dependency> <groupId>io.github.ehayik</groupId> <artifactId>jmaskify</artifactId> <version>1.1.0</version> </dependency> ``` This includes [jackson-core](https://github.com/FasterXML/jackson-core) and [jackson-databind](https://github.com/FasterXML/jackson-databind) for JSON processing. All dependencies and versions are managed in the project's `pom.xml` ### Basic Usage #### 1. Simple String Masking The quickest way to mask sensitive data: ```java // Mask a credit card number var creditCardNumber = "4289-3874-8064-8976"; var masked = Masker.creditCard().apply(creditCardNumber); // Result: "****-****-****-8976" // Mask an email address var email = "[email protected]"; var maskedEmail = Masker.fixedLength().apply(email); // Result: "****************" ``` #### 2. JSON Masking For masking fields within JSON objects: ```java String json = """ { "name": "John Doe", "age": 30, "contactInfo": { "email": "[email protected]", "phone": "123-456-7890" }, "creditCard": "1234-5678-9012-3456" } """; // Create a JsonMasker instance var masker = Masker.json() .prettify(true) .withProperty("email") // Default fixed pattern masking .withProperty("phone", Masker.base64()) .withProperty("creditCard", Masker.creditCard('X')) .withProperty("name", Masker.delegate(value -> "■■■■■■")); // Apply masking var maskedJson = masker.apply(json); /* Result: { "name": "■■■■■■", "age": 30, "contactInfo": { "email": "***************", "phone": "MTIzLTQ1Ni03ODkw" }, "creditCard": "XXXX-XXXX-XXXX-3456" } */ ``` > [!INFO] > Non-string values (numbers, booleans, nulls) are preserved without masking. ##### Masking string values within a JSON array *JMaskify* provides powerful capabilities for masking string values within JSON arrays. Here are examples of different array masking scenarios: ###### Example 1: Simple Array of Strings When you need to mask an array of sensitive string values, such as credit card numbers: ```java String json = """ { "name": "John Doe", "creditCards": [ "1234-5678-9012-3456", "4289-3874-8064-8976" ] } """; var masker = JsonMasker.builder() .withProperty("creditCards", Masker.creditCard('X')) .build(); var maskedJson = masker.apply(json); /* Result: { "name": "John Doe", "creditCards": [ "XXXX-XXXX-XXXX-3456", "XXXX-XXXX-XXXX-8976" ] } */ ``` ###### Example 2: Arrays with Mixed Value Types *JMaskify* can handle arrays containing a mix of different value types, masking only the string values: ```java String json = """ { "name": "John Doe", "mixedArray": [ "sensitive-string-data", 42, true, null, {"nestedKey": "nestedValue"}, ["nested", "array"] ] } """; var masker = JsonMasker.builder() .withProperty("mixedArray", Masker.fixedLength()) .build(); var maskedJson = masker.apply(json); /* Result: { "name": "John Doe", "mixedArray": [ "*********************", 42, true, null, {"nestedKey": "***********"}, ["******", "*****"] ] } */ ``` ###### Example 3: Nested Arrays *JMaskify* handles nested arrays with specific masking behavior: ```java String json = """ { "name": "John Doe", "nestedArrays": [ ["sensitive-outer-inner", "another-value"], 42, ["not-masked-1", "not-masked-2"] ] } """; var masker = JsonMasker.builder() .withProperty("nestedArrays", Masker.fixedLength()) .build(); var maskedJson = masker.apply(json); /* Result: { "name": "John Doe", "nestedArrays": [ ["*********************", "*************"], 42, ["************", "************"] ] } */ ``` > [!INFO] > All string values within nested arrays are masked consistently, regardless of their position or nesting level. #### 3. Multiline Text Masking When working with log files or other text that spans multiple lines, you can use multiline text masking to identify and mask patterns: ```java String logContent = """ 2023-05-15 INFO User [email protected] logged in 2023-05-15 INFO IP Address: 192.168.1.1 """; // Create a MultilinePatternMasker instance var masker = Masker.multilinePattern() .withMaskPattern("(\\d+\\.\\d+\\.\\d+\\.\\d+)"); // Apply masking var maskedContent = masker.apply(logContent); // Result: // 2023-05-15 INFO User [email protected] logged in // 2023-05-15 INFO IP Address: ********** ```