Javatpoint Logo

how to implement data masking in java?

By: k.mash*** On: Fri May 23 14:00:09 IST 2014     Question Reputation5 Answer Reputation0 Quiz Belt Series Points6  11Blank User
Give me any idea about data masking implementation so that we can provide data privacy in java project in easy manner...

It will be grateful if u could help me...


Data masking is nothing but obscuring specific records within the database. 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 the code level can we implement the below requirements.

1. Data mask on the screen display for SSN #, bank card, Medical Info # etc.
2. Data Mask on export to file with above fields.
Image Created0Down

By: [email protected] On: Fri May 23 16:16:20 IST 2014 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :2Yes3No
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.
In data masking, the format of data remains the same; only values are changed.

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

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();
Image Created0Down

By: [email protected] On: Mon May 26 16:13:06 IST 2014 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :1Yes0No