How to generate hashkey

Highlighted
Nine Stars

How to generate hashkey

Hello 

 

Can anyone suggest me, how to generate a hashcode using four business elements, which are coming from a source, am not familiar with java to write a routine for 4 business elements. i found a component taddCRCrow,but this can be used to get surrogate key not a hash code value, do we have any good component which can produce hash code, or else can any help me out how to write java code using 4 business elements, all this 4 attributes are string datatype

 

Thanks In Advance

Manish


Accepted Solutions
Fifteen Stars TRF
Fifteen Stars

Re: How to generate hashkey

Here is a piece of code you can use to generate a MD5 string from an input (called strCode):

package routines;
import java.security.*;
public class GetHashCode {
	public static String getMD5(String strCode) {
		java.security.MessageDigest msg;
		String digest1 = "";
		try {
			msg = java.security.MessageDigest.getInstance("MD5");
			msg.update(strCode.getBytes(), 0, strCode.length());
			digest1 = new java.math.BigInteger(1, msg.digest()).toString(32);
		}
		catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return digest1.toUpperCase();
	}
}

Create the routine and copy/past the code then start using it from anywhere in your jobs using the following expression:

GetHashCode.getMD5(row1.field1 + row1.field2 + row1.field3 + row1.field4)

 


TRF

All Replies
Fifteen Stars TRF
Fifteen Stars

Re: How to generate hashkey

Here is a piece of code you can use to generate a MD5 string from an input (called strCode):

package routines;
import java.security.*;
public class GetHashCode {
	public static String getMD5(String strCode) {
		java.security.MessageDigest msg;
		String digest1 = "";
		try {
			msg = java.security.MessageDigest.getInstance("MD5");
			msg.update(strCode.getBytes(), 0, strCode.length());
			digest1 = new java.math.BigInteger(1, msg.digest()).toString(32);
		}
		catch (NoSuchAlgorithmException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return digest1.toUpperCase();
	}
}

Create the routine and copy/past the code then start using it from anywhere in your jobs using the following expression:

GetHashCode.getMD5(row1.field1 + row1.field2 + row1.field3 + row1.field4)

 


TRF
Nine Stars

Re: How to generate hashkey

@TRF Thank you so much for very swift response and  it worked out.

Fifteen Stars TRF
Fifteen Stars

Re: How to generate hashkey

You're welcome

TRF

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog