title: How to generate AWS signature from JMeter?
body: <p>Here is my code in the JSR223 PreProcessor.</p>
  
  <pre><code>import javax.crypto.Mac
  import javax.crypto.spec.SecretKeySpec
  import java.security.InvalidKeyException
  import java.security.MessageDigest
  import groovy.json.JsonSlurper
  import java.text.SimpleDateFormat
  
  static byte[] HmacSHA256(String data, byte[] key) throws Exception {
  String algorithm="HmacSHA256";
  Mac mac = Mac.getInstance(algorithm);
  mac.init(new SecretKeySpec(key, algorithm));
  return mac.doFinal(data.getBytes("UTF8"));
  </code></pre>
  
  <p>}</p>
  
  <pre><code>static byte[] getSignatureKey(String key, String dateStamp, String regionName, String serviceName) throws Exception {
  byte[] kSecret = ("AWS4" + key).getBytes("UTF8");
  byte[] kDate = HmacSHA256(dateStamp, kSecret);
  byte[] kRegion = HmacSHA256(regionName, kDate);
  byte[] kService = HmacSHA256(serviceName, kRegion);
  byte[] kSigning = HmacSHA256("aws4_request", kService);       
  return kSigning;    
  </code></pre>
  
  <p>}</p>
  
  <p>Example parameter values to the function getSignatureKey are (these I am passing to the Parameters section of the JSR223 PreProcessor as variables)</p>
  
  <pre><code>key = eC6hEyRSTXMzsG6+juOObz8LbXb36iEYW7PPN1MJ
  dateStamp = 20190123T083434Z
  regionName = us-west-2
  serviceName = test-mlp-us-west-2-4023179c-7708-4c5e-a831-28259b8a8872.s3.us-west-2.amazonaws.com
  </code></pre>
  
  <p>This code is not working and not generating the AWS signature.</p>
  
  <p>Here is the sample Signature value I need to get </p>
  
  <pre><code>Signature=2a6092ec4ff49dc9j3b92d436635a57f312753kcc9f553ce1718b9b1594c4362
  </code></pre>
  
  <p>1.What is wrong with this code?
  2.How can I assign the AWS signature to a variable and use in the JMeter?</p>