Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

Labels (3)
1 Solution

Accepted Solutions
TRF
Champion II
Champion II

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)

 

View solution in original post

4 Replies
TRF
Champion II
Champion II

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)

 

Anonymous
Not applicable
Author

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

TRF
Champion II
Champion II

You're welcome
Anonymous
Not applicable
Author

Is it possible to get the result only in integers.