I'm trying to calculate a sha256 hash in Groovy version 2.4.16. This is part of a jmeter test and that is the version of Groovy it supports, and I don't think I can change that. I'm aware that in Groovy 2.5 you can use code like this:
def challenge = verifier.digest('SHA-256');
log.info 'challenge' + challenge
but this doesn't work/exist in 2.4. How can I do this in Groovy 2.4?
The error I get with the above code is:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.digest() is applicable for argument types: (java.lang.String) values: [SHA-256]
Possible solutions: getAt(java.lang.String), next(), size(), toSet(), size(), toList()
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
at javax.script.CompiledScript.eval(Unknown Source) ~[?:1.8.0_221]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:44) [ApacheJMeter_components.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:935) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:537) [ApacheJMeter_core.jar:5.1.1 r1855137]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137]
...