Skip to content

Instantly share code, notes, and snippets.

@virtualhobbit
Created July 13, 2020 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save virtualhobbit/147147cf1af9fee5aa47e1bb58238464 to your computer and use it in GitHub Desktop.
Save virtualhobbit/147147cf1af9fee5aa47e1bb58238464 to your computer and use it in GitHub Desktop.
// Hash the payload
attHashedPayload = CryptoEncoding.base64toHex(CryptoDigest.sha256(attBody));
// Format the date
attAmzDate = System.getModule("com.hobbitcloud.aws.date").getAmzDate(new Date().toISOString());
var canonicalUri = "/2013-04-01/hostedzone/" + attHostedZone + "/rrset";
var canonicalQueryString = "";
var canonicalHeaders = 'host:' + attUrl + '\n' +
'x-amz-content-sha256:' + attHashedPayload + '\n' +
'x-amz-date:' + attAmzDate + '\n'
attSignedHeaders = 'host;x-amz-content-sha256;x-amz-date';
// Define the request
var canonicalRequest = attHttpRequestMethod + '\n' + canonicalUri + '\n' + canonicalQueryString + '\n' + canonicalHeaders + '\n' + attSignedHeaders + '\n' + attHashedPayload;
System.log("The canonical request is: " + '\n' + '\n' + canonicalRequest + '\n');
// Hash the request
attCanonicalRequestHash = CryptoEncoding.base64toHex(CryptoDigest.sha256(canonicalRequest));
System.log("The canonical request hash is: " + attCanonicalRequestHash);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment