Calculate SHA1 or MD5 hash in iReport

How to calculate SHA1 or MD5 hash in iReport when running a report? I need to compare a pre-computed hash with a field (string) managed by a database.

Using iReport 2.0.5 (Old) and Report Engine is built into the commercial application.

+3
source share
1 answer

I used the iReport and Jasper reports a few years ago and I donโ€™t remember the details, but I remember that you could somehow evaluate the Java code. Using this function, you can calculate MD5 in several lines:

String encryptionAlgorithm = "MD5";
String valueToEncrypt = "StackOverflow";
MessageDigest msgDgst = MessageDigest.getInstance(encryptionAlgorithm);
msgDgst.update(valueToEncrypt.getBytes(), 0, valueToEncrypt.length());
String md5 = new BigInteger(1, msgDgst.digest()).toString(16) ;
System.out.println(md5);

You must import java.math.BigInteger, java.security.MessageDigest and java.security.NoSuchAlgorithmException;

SHA1, :

String encryptionAlgorithm = "SHA-1";
String valueToEncrypt = "StackOverflow";
MessageDigest msgDgst = MessageDigest.getInstance(encryptionAlgorithm);
byte[] sha1hash = new byte[40];
msgDgst.update(valueToEncrypt.getBytes(), 0, valueToEncrypt.length());
sha1hash = md.digest();

, http://www.eakes.org/77/java-injection-in-jasper-reports/

+5

Source: https://habr.com/ru/post/1720486/


All Articles