Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Nreimondo1645519314
Contributor III
Contributor III

md5 calculation in route

Hi all,

Is there an easy way to calculate a hash-key in a route? I know there is a component in jobs to do that, but I don't want to use a job in my route.

I'm working with messages from a queue (ActiveMQ), so there will be all kinds of structures of messages to calculate a hash for.

I would like to have a route like this:

Input JMS -> Hash calculation of message body -> Output JMS

I hope this is possible and I'm looking forward to read the possibilities.

Labels (2)
1 Solution

Accepted Solutions
Nreimondo1645519314
Contributor III
Contributor III
Author

Hi,

 

Thanks for replying.

 

I fixed it using function DigestUtils.sha256Hex() in a cProcessor component.

View solution in original post

4 Replies
Anonymous
Not applicable

Hello,

You are able to create a custom bean with the hashing code and just call it in your route.

 

package beans;

 

import java.io.IOException;

import java.io.InputStream;

import java.security.DigestInputStream;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

 

/**

* Generates a hash value based on the provided inputStream.

*

* For example returns a sha-256 hash of a file stream.

*

*/

public class HashGenerator {

 

public static String DEFAULT_HASH_ALGORYTHM = "SHA-256";

protected String hashAlgo;

public HashGenerator(String hashAlgorithm) throws NoSuchAlgorithmException {

this.hashAlgo = hashAlgorithm;

// Test if algorithm exists

MessageDigest.getInstance(hashAlgo);

}

public HashGenerator() throws NoSuchAlgorithmException {

this(DEFAULT_HASH_ALGORYTHM);

}

public String checksum(InputStream stream) throws IOException, NoSuchAlgorithmException {

 

if (stream == null) {

return null;

}

MessageDigest md = MessageDigest.getInstance(hashAlgo);

// file hashing with DigestInputStream

try (DigestInputStream dis = new DigestInputStream(stream, md)) {

while (dis.read() != -1) ; //empty loop to clear the data

md = dis.getMessageDigest();

dis.close();

}

stream.close();

 

// bytes to hex

StringBuilder result = new StringBuilder();

for (byte b : md.digest()) {

result.append(String.format("%02x", b));

}

return result.toString();

}

 

}

 

0695b00000fL9cyAAC.pngFeel free to let us know if it is what you are looking for.

Best regards

Sabrina

 

Nreimondo1645519314
Contributor III
Contributor III
Author

Hi,

 

Thanks for replying.

 

I fixed it using function DigestUtils.sha256Hex() in a cProcessor component.

Anonymous
Not applicable

Hello,

Thanks for sharing your solution with us and feel free to let us know if there is any further help we can give.

Best regards

Sabrina

SterreKapteijns
Partner - Contributor III
Partner - Contributor III

Using the Hashify API would also be an option I guess.