I am trying to compute the Apex equivalent of the following -
var shaBodyContent = CryptoJS.HmacSHA256(stringToSign, postman.getEnvironmentVariable("HMAC_SS"));
var b64BodyContent = shaBodyContent.toString(CryptoJS.enc.Base64);
Apex:
Blob mac = Crypto.generateMac('hmacSHA256',blob.valueOf(stringToSign),blob.valueOf(secretAccessKey));
system.debug('This is the shaBodyContent: ' +mac); // debug log displays Blob[32]
String signature = EncodingUtil.base64Encode(mac);
system.debug(This is b64BodyContent :' +signature);
This, system.debug('This is the shaBodyContent: ' +mac); displays Blob[32] and this, system.debug(This is b64BodyContent :' +signature); displays a string
However when I create a raw signature as follows -
String authorization_header = 'RouteOne' + ' ' + accessKeyID + ':' + signature;
I get an error.
Status Code: 401
Status Message: Unauthorized
Error Message: "The authenticity of the request could not be verified","developerMessage":"The HMAC-SHA256 headers encoded with the secret key associated with the Access Key Id provided did not match the encoded value provided in the request Authorization header"
b64bodyContent
in JS same as the value ofsignature
in Apex?