Search Courses

Search Courses
Home / Blog
Informatica: Using Java transformation for encrypting data

Informatica: Using Java transformation for encrypting data

Posted on : 06,Jul 2014 5895

SHA-1 encryption implemented using Java transformation in Informatica

My current project had a requirement to use SHA-1 encryption in informatica. SHA is secure hash algorithm , SHA-1 in particular generate a 20byte hash. Informatica expression transformation by default support encryption like MD5, though it does not support encryption like SHa-1 or SHA-256 etc. Through this exercise I am trying to show the usage of Java transformation in informatica to achieve this.

The PowerCenter Client uses the Java Development Kit (JDK) to compile the Java code and generate byte code for the transformation. The PowerCenter Client stores the byte code in the PowerCenter repository. The Integration Service uses the Java Runtime Environment (JRE) to execute generated byte code at run time.When the Integration Service runs a session with a Java transformation, the Integration Service uses the JRE to execute the byte code and process input rows and generate output rows.

I have found java transformation very useful when you want to make it run as an active transformation. For e.g generate output rows based on certain criteria. Lot of tasks which may get complicated using a normalizer or you have to jump lot of hoops can be made easy by a few lines of code in Java transformation.

For my current task in hand, I used Java library message digest which has all this encryption algorithm. So first thing is to include this library in code. This can be done in import package tab on java code. I have used java transformation as passive transformation here, since I am just using java function.

import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;




Since I am processing a particular column, say I am encrypting a key or a column to SHA-1 hash , I will write my code on "On Input Row tab". All the ports are available on left side tab and can be used within the code, just like used in any other transformation.

 try {
            MessageDigest md = MessageDigest.getInstance("SHA-1");
            byte[] messageDigest = md.digest(AUDIT_KEY.getBytes());
            BigInteger number = new BigInteger(1, messageDigest);
            String hashtext = number.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            ENC_KEY= hashtext;
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
 

You can have helper code incase you are instantiating a class etc. "On end of Data" tab can be used to write code for operations after the entire data is processed. For e.g you want  to have a count or log of operation you completed in java transformation. Since I don't have any I am not using these tabs. Once code is written, you can compile the code and check for errors.

For ETL resources here goes the explanation of above java code.

Once the packages are imported, you can instantiate the message digest class for "SHA-1" algorithm.

MessageDigest md = MessageDigest.getInstance("SHA-1");

Next three lines shows the conversion , since my port is number , I am converting to string and padding 0 to make it length of 32, not necessay if you dont want full 32 characters.

Once the encrypted key is generated, pass that too output port.


ENC_KEY= hashtext;

A general try and catch is used to handle exceptions.


Join the discussion

Improve the thread with your input and questions.
Hari Ramesh
Big Data and Analytics Architect at Abbvie Inc

Member Since : Feb, 2014

LIBERTYVILLE Illinois

LinkedIn Twitter

Interested in Informatica? We will notify you when knowledge is shared.