Project: talenddataquality
Issue TDQ-11493: Create a Data masking routines
Create a data masking routine using the data masking library. Take the following code and refactor it so that - the java code style respects our standard (no underscore, no uppercase for variables,...) - there is no hard coded string (secret strings must be parameters of the functions). - remove the "DM_" It's not needed to understand the method name. - it has a clear documentation {code:java} package routines; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Calendar; import java.util.Random; import java.security.*; import java.security.spec.KeySpec; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESKeySpec; import sun.misc.*; import java.util.*; /* * user specification: the function's comment should contain keys as follows: 1. write about the function's comment.but * it must be before the "{talendTypes}" key. * * 2. {talendTypes} 's value must be talend Type, it is required . its value should be one of: String, char | Character, * long | Long, int | Integer, boolean | Boolean, byte | Byte, Date, double | Double, float | Float, Object, short | * Short * * 3. {Category} define a category for the Function. it is required. its value is user-defined . * * 4. {param} 's format is: {param} [()] [ : ] * * 's value should be one of: string, int, list, double, object, boolean, long, char, date. 's value is the * Function's parameter name. the {param} is optional. so if you the Function without the parameters. the {param} don't * added. you can have many parameters for the Function. * * 5. {example} gives a example for the Function. it is optional. * * Author: rzenker@talend.com * Date: */ public class DataMasking { /** * MD2: Calculate MD2 hash value from String. * * * {talendTypes} String * * {Category} User Defined * * {param} string("foo") input: The string need to be masked. * * {example} CreateMD5("foo") * @throws NoSuchAlgorithmException */ public static String DM_CreateMD2(String message) throws NoSuchAlgorithmException {	if (message == null) {	return "Input String for MD2 caluclation is missing";	} else {	/*MD2 Calculation */ MessageDigest thisMD2 = MessageDigest.getInstance("MD2"); thisMD2.reset(); thisMD2.update(message.getBytes()); byte[] result = thisMD2.digest(); /* Return */ StringBuffer hexString = new StringBuffer(); for (int i=0; i= 0){	hexString.append("0");	} hexString.append(Integer.toHexString(0xFF & result[i])); } return hexString.toString();	} } /** * MD5: Calculate MD5 hash value from String. * * * {talendTypes} String * * {Category} User Defined * * {param} string("foo") input: The string need to be masked. * * {example} CreateMD5("foo") * @throws NoSuchAlgorithmException */ public static String DM_CreateMD5(String message) throws NoSuchAlgorithmException {	if (message == null) {	return "Input String for MD5 calculation is missing";	} else {	/*Calculation */ MessageDigest thisMD5 = MessageDigest.getInstance("MD5"); thisMD5.reset(); thisMD5.update(message.getBytes()); byte[] result = thisMD5.digest(); /* Return */ StringBuffer hexString = new StringBuffer(); for (int i=0; i= 0){	hexString.append("0");	} hexString.append(Integer.toHexString(0xFF & result[i])); } return hexString.toString();	} } /** * CreditCard Masking: Masks a 16 digit credit card number with a defined character from 5th to 12th place. * * * {talendTypes} String * * {Category} User Defined * * {param} string("ccnum") input: The string needs to be masked. * {param} string("maskingChar") input: The masking Character. * * {example} CCcardMasking("ccnum","maskinChar") * @throws NoSuchAlgorithmException */ public static String DM_CCcardMasking(String ccnum, String maskingChar) throws NoSuchAlgorithmException { int total = ccnum.length(); int startlen=4,endlen = 4; int masklen = total-(startlen + endlen) ;	if (ccnum.length() != 16) {	return "No Credit Card Number - length not 16 char";	}	else { StringBuffer maskedbuf = new StringBuffer(ccnum.substring(0,startlen)); for(int i=0;i
Story points: 5