Search code examples
jmetersha1cryptojsbeanshell

How to generate hash(SHA1) using beanshell in JMeter?


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


Solution

  • 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.