2

How do I want to generate a hash using beanshell(SHA1) in JMeter to sign up to a application?

I'm not able to get a substantial answer yet from net

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
Vinyasjain77
  • 31
  • 1
  • 7
  • There is some script for SHA1 here: http://stackoverflow.com/questions/1589996/calculate-sha1-or-md5-hash-in-ireport Try it, maybe it will help. – Faflok Oct 15 '15 at 12:38

2 Answers2

3

Generating a hash is pretty easy, just use DigestUtils class from Apache Commons Codec library (it's a part of JMeter so you won't need to install anything external)

Something like:

import org.apache.commons.codec.digest.DigestUtils;

String foo = "bar";
String sha1Hex = DigestUtils.sha1Hex(foo);

Usually SHA1 is being required for signing requests to OAuth-protected applications, if it is your case, I believe How to Run Performance Tests on OAuth Secured Apps with JMeter will be extremely helpful.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

There's a new JMeter function __digest, currently in nightly builds which can be used to encode strings

In your case to save in sha1Value variable the result of myVar variable use the following:

${__digest(SHA-1,${myVar},,,sha1Value)}

4th parameter is uppercase, so you can send true to automatically uppercase it.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233