HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
1. Feel Free to ask and submit anything on and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.

java-masking: What is data masking?

Give me any idea about data masking implementation in java so that we can provide data privacy in java project in easy manner.

java x 211
masking x 1
Posted On : 2014-05-24 03:14:55.0
profile Garima Gupta - Garima Gupta


Data masking is a method of creating a structurally similar version of an organization´s data that can be used for purposes such as software testing and user training. The purpose of data masking is to protect the actual data while having a functional substitute when the real data is not required. Masking of data ensures that sensitive data is replaced with realistic but not real data in testing environment thus achieving both the aims ? protecting sensitive data and ensuring that test data is valid and testable.

In data masking, the format of data remains the same; only values are changed. The data may be changed in a number of ways, including encryption, character or word substitution and character shuffling. Whatever method is chosen, the values must be changed in some way that makes detection or reverse engineering impossible.

Data masking is not only just about Testing the Data. In fact this concept can be applied to every situation where an organization does not want to reveal real data. For Example: Salary information of every employee. Data masking techniques can be applied here as well. There can be many such scenarios.

Vendors of data masking products include Compuware, dataguise, IBM, Informatica and Oracle, etc.

To implement Data masking in java, let´s focus on following example in which we mask some ATM card numbers:

***************************** Data Masking Example in java *****************************

* Applies the specified mask to the card number.
* @param cardNumber The card number in plain format
* @param mask The number mask pattern. Use # to include a digit from the
* card number at that position, use x to skip the digit at that position
* @return The masked card number
public static String maskCardNumber(String cardNumber, String mask) {

// format the number
int index = 0;
StringBuilder maskedNumber = new StringBuilder();
for (int i = 0; i < mask.length(); i++) {
char c = mask.charAt(i);
if (c == ´#´) {
} else if (c == ´x´) {
} else {

// return the masked number
return maskedNumber.toString();

Sample Calls:
System.out.println(maskCardNumber("1234123412341234", "xxxx-xxxx-xxxx-####"));
> xxxx-xxxx-xxxx-1234

System.out.println(maskCardNumber("1234123412341234", "##xx-xxxx-xxxx-xx##"));
> 12xx-xxxx-xxxx-xx34

Posted On : 2014-05-24 03:40:27
Satisfied : 4 Yes  0 No
profile Rishi Kumar - Rishi Kumar
Reply This Thread

Post Answer
Please Login First to Post Answer: Login login with facebook -