Skip to content

Instantly share code, notes, and snippets.

@tianying484
Forked from lishenzhi/jmeter-sha256
Created July 6, 2018 09:12
Show Gist options
  • Save tianying484/605a6c3c904b61aa7dc7df8e40f78939 to your computer and use it in GitHub Desktop.
Save tianying484/605a6c3c904b61aa7dc7df8e40f78939 to your computer and use it in GitHub Desktop.
jmeter sha256 signature
// beanshell preprocessor
import org.apache.commons.httpclient.auth.DigestScheme; // necessary imports
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jmeter.protocol.http.control.Header;
long timestamp = System.currentTimeMillis() / 1000L;
String clientID = "***";
String clientSecret = "****";
String authClient = "Doorman-SHA256 Credential=" + clientID;
String combined = clientID + clientSecret + String.valueOf(timestamp);
String sha256hex = DigestUtils.sha256Hex(combined);
sampler.getHeaderManager().add(new Header("Signature", sha256hex));
sampler.getHeaderManager().add(new Header("Authorization", authClient));
sampler.getHeaderManager().add(new Header("Timestamp", String.valueOf(timestamp)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment