Skip to content

Instantly share code, notes, and snippets.

@lishenzhi
Last active August 10, 2023 15:41
Show Gist options
  • Save lishenzhi/c3bc1cc49d74da0039daf2f3fb0f953d to your computer and use it in GitHub Desktop.
Save lishenzhi/c3bc1cc49d74da0039daf2f3fb0f953d 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