One Star

How can we encrypt column value in talend Please help

Hi Team,
I need to encrypt particular attribute value .. how  can we achive this through talend .Please help me
Regards
Mohini Sharrmaa M
4 REPLIES
Fifteen Stars

Re: How can we encrypt column value in talend Please help

You can do this with a bit of Java in a tMap. Create a routine to encrypt your data (there are lots of examples here http://www.example-code.com/java/encryption.asp) and use the routine in a tMap. 
Rilhia Solutions
One Star

Re: How can we encrypt column value in talend Please help

Could you please give me the code if possible or function which I can use to call routine in tmap
thanks in Advance
Mohini
Fifteen Stars

Re: How can we encrypt column value in talend Please help

First you need to create your routine. An example of a routine for encryption can be seen below (it's been a while since I wrote this and I am not certain it works)....
package routines;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.Formatter;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class EncryptionUtilities {

private static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";

private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();

for (byte b : bytes) {
formatter.format("%02x", b);
}

return formatter.toString();
}

public static String calculateRFC2104HMAC(String data, String key)
throws SignatureException, NoSuchAlgorithmException, InvalidKeyException
{
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
return toHexString(mac.doFinal(data.getBytes()));
}

}

To call this in the tMap you simply use the code.....
routines.EncryptionUtilities.calculateRFC2104HMAC(row1.data, "myKey")

....in the column you want to encrypt.
Please note that this is not meant for you to copy (you can, but it will need testing since it is a bit of code I quickly found on my machine), but as an example of how to do this.
Rilhia Solutions
One Star

Re: How can we encrypt column value in talend Please help

thank you so much