Reputation: 3481
How do you call HMac-Sha1 in a custom extension javascript? I need to generate a custom signature for my RESTful API.
I need to call a dynamic value from the JavaScript call using the Paw JS API. For instance, I need to compute an HMAC + SHA1 hash from my JS code, and for that I thought it would be convenient to use the existing "HMAC-SHA1" dynamic value.
How do I do that?
Upvotes: 0
Views: 277
Reputation: 3481
You can do it by instantiating a new DynamicValue
setting its values, wrap it in a DynamicString
and evaluate it.
Note, the dynamic values themselves aren't documented yet. But you have the doc of DynamicValue
and DynamicString
.
Here's the code:
function evaluate(context){
// create a dynamic value of that type
var dv = DynamicValue('com.luckymarmot.HMACDynamicValue');
// set its properties
dv.algorithm = 1; // (not documented) algorithm = 1 for SHA1
dv.input = "Something to Hash"; // input string
dv.key = "HASH_KEY"; // HMAC key
// wrap in a (dynamic) string
var string = DynamicString(dv)
// evaluate the string
return string.getEvaluatedString();
};
Upvotes: 0