3

I'm trying to produce a HMAC SHA256 signature for a SOAP/XML-RPC JMeter Request that I am building. I have found a JavaScript library that should do the trick for me:

http://code.google.com/p/crypto-js/#HMAC

The issue is that I can't find a way to call the external JavaScript files methods from JMeter.

Any help would really be appreciated with this or a suggestion for an alternative to preform the task.

Mike
  • 827
  • 11
  • 27

1 Answers1

3

You don't need to use any external JS libraries to generate HMAC. This functionality is available in Java SE. You can use Beanshell Sampler to execute Java code.

If this functionality wouldn't be available in Java SE, you could:

  • use OS Process Sampler
  • use BSF Sampler, set language to javascript and attach file with script
  • put Jar of chosen library to Jmeter's lib folder. Then this library will be loaded by JMeter at startup time and you can use it through Beanshell sampler
Community
  • 1
  • 1
Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
  • Thanks for the response. I'm new to JMeter and BeanShell and am from a C# background so it may take me some time to implement this through Java/BeanShell. I'll look into your suggestion as an alternative to calling the external JavaScript files methods. Does anybody know if it is possible to call external JavaScript methods from JMeter? – Mike Nov 14 '12 at 09:35
  • 1
    @Mike as I told it's possible using OS Process Sampler. But it will be better to use Beanshell – Andrei Botalov Nov 14 '12 at 09:38
  • 1
    You can also use BSF Sampler, set language to javascript and attach file with script – Andrei Botalov Nov 14 '12 at 09:40
  • Thanks for pointing me in the right direction here. Due to time constraints I stuck with the JavaScript solution, which I am more comfortable with. I used the BSF sampler as per your latest comment but still have problems calling the code from external JS file. In the end to get me over the hump, I just pasted the code from the two file I wanted "hmac-sha256.js" and "enc-base64-min.js" into the "Script to run" text area. I then called it like so: – Mike Nov 14 '12 at 15:47
  • 2
    Opps. Posted before finishing comment: `var hash = CryptoJS.HmacSHA256("TextToHash", "Secret"); hash = hash.toString(CryptoJS.enc.Base64); vars.put("hash", hash);` I was then able to reference this variable in my request sampler like so `${hash}` – Mike Nov 14 '12 at 15:55